#include <config.h>
#include "bridge.h"
+#include "byte-order.h"
#include <assert.h>
#include <errno.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <unistd.h>
#include "bitmap.h"
+#include "classifier.h"
#include "coverage.h"
#include "dirs.h"
#include "dpif.h"
#include "vswitchd/vswitch-idl.h"
#include "xenserver.h"
#include "vlog.h"
-#include "xtoxll.h"
#include "sflow_api.h"
-VLOG_DEFINE_THIS_MODULE(bridge)
+VLOG_DEFINE_THIS_MODULE(bridge);
struct dst {
uint16_t vlan;
static struct iface *iface_from_dp_ifidx(const struct bridge *,
uint16_t dp_ifidx);
static void iface_set_mac(struct iface *);
+static void iface_set_ofport(const struct ovsrec_interface *, int64_t ofport);
static void iface_update_qos(struct iface *, const struct ovsrec_qos *);
static void shash_from_ovs_idl_map(char **keys, char **values, size_t n,
error = netdev_open(&netdev_options, &iface->netdev);
if (iface->netdev) {
- netdev_get_carrier(iface->netdev, &iface->enabled);
+ iface->enabled = netdev_get_carrier(iface->netdev);
}
shash_destroy(&options);
if (cb(br, iface, aux)) {
j++;
} else {
+ iface_set_ofport(iface->cfg, -1);
iface_destroy(iface);
}
}
* should not be and in fact is not directly involved in that. But
* ovs-vswitchd needs to make sure that ovsdb-server can reach the managers, so
* it has to tell in-band control where the managers are to enable that.
+ * (Thus, only managers connected in-band are collected.)
*/
static void
-collect_managers(const struct ovsrec_open_vswitch *ovs_cfg,
- struct sockaddr_in **managersp, size_t *n_managersp)
+collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg,
+ struct sockaddr_in **managersp, size_t *n_managersp)
{
struct sockaddr_in *managers = NULL;
size_t n_managers = 0;
+ struct shash targets;
+ size_t i;
- if (ovs_cfg->n_managers > 0) {
- size_t i;
+ /* Collect all of the potential targets, as the union of the "managers"
+ * column and the "targets" columns of the rows pointed to by
+ * "manager_options", excluding any that are out-of-band. */
+ shash_init(&targets);
+ for (i = 0; i < ovs_cfg->n_managers; i++) {
+ shash_add_once(&targets, ovs_cfg->managers[i], NULL);
+ }
+ for (i = 0; i < ovs_cfg->n_manager_options; i++) {
+ struct ovsrec_manager *m = ovs_cfg->manager_options[i];
- managers = xmalloc(ovs_cfg->n_managers * sizeof *managers);
- for (i = 0; i < ovs_cfg->n_managers; i++) {
- const char *name = ovs_cfg->managers[i];
- struct sockaddr_in *sin = &managers[i];
+ if (m->connection_mode && !strcmp(m->connection_mode, "out-of-band")) {
+ shash_find_and_delete(&targets, m->target);
+ } else {
+ shash_add_once(&targets, m->target, NULL);
+ }
+ }
+
+ /* Now extract the targets' IP addresses. */
+ if (!shash_is_empty(&targets)) {
+ struct shash_node *node;
- if ((!strncmp(name, "tcp:", 4)
- && inet_parse_active(name + 4, JSONRPC_TCP_PORT, sin)) ||
- (!strncmp(name, "ssl:", 4)
- && inet_parse_active(name + 4, JSONRPC_SSL_PORT, sin))) {
+ managers = xmalloc(shash_count(&targets) * sizeof *managers);
+ SHASH_FOR_EACH (node, &targets) {
+ const char *target = node->name;
+ struct sockaddr_in *sin = &managers[n_managers];
+
+ if ((!strncmp(target, "tcp:", 4)
+ && inet_parse_active(target + 4, JSONRPC_TCP_PORT, sin)) ||
+ (!strncmp(target, "ssl:", 4)
+ && inet_parse_active(target + 4, JSONRPC_SSL_PORT, sin))) {
n_managers++;
}
}
}
+ shash_destroy(&targets);
*managersp = managers;
*n_managersp = n_managers;
COVERAGE_INC(bridge_reconfigure);
- collect_managers(ovs_cfg, &managers, &n_managers);
+ collect_in_band_managers(ovs_cfg, &managers, &n_managers);
/* Collect old and new bridges. */
shash_init(&old_br);
struct ovsrec_controller **controllers;
size_t n_controllers;
bool had_primary;
+ const char *disable_ib_str;
+ bool disable_in_band = false;
struct ofproto_controller *ocs;
size_t n_ocs;
size_t i;
- ofproto_set_extra_in_band_remotes(br->ofproto, managers, n_managers);
+
+ /* Check if we should disable in-band control on this bridge. */
+ disable_ib_str = bridge_get_other_config(br->cfg, "disable-in-band");
+ if (disable_ib_str && !strcmp(disable_ib_str, "true")) {
+ disable_in_band = true;
+ }
+
+ if (disable_in_band) {
+ ofproto_set_extra_in_band_remotes(br->ofproto, NULL, 0);
+ } else {
+ ofproto_set_extra_in_band_remotes(br->ofproto, managers, n_managers);
+ }
had_primary = ofproto_has_primary_controller(br->ofproto);
n_controllers = bridge_get_controllers(br, &controllers);
}
bridge_configure_local_iface_netdev(br, c);
- bridge_ofproto_controller_from_ovsrec(c, &ocs[n_ocs++]);
+ bridge_ofproto_controller_from_ovsrec(c, &ocs[n_ocs]);
+ if (disable_in_band) {
+ ocs[n_ocs].band = OFPROTO_OUT_OF_BAND;
+ }
+ n_ocs++;
}
ofproto_set_controllers(br->ofproto, ocs, n_ocs);
if (!n_controllers
&& ofproto_get_fail_mode(br->ofproto) == OFPROTO_FAIL_STANDALONE) {
union ofp_action action;
- struct flow flow;
+ struct cls_rule rule;
memset(&action, 0, sizeof action);
action.type = htons(OFPAT_OUTPUT);
action.output.len = htons(sizeof action);
action.output.port = htons(OFPP_NORMAL);
- memset(&flow, 0, sizeof flow);
- ofproto_add_flow(br->ofproto, &flow, OVSFW_ALL, 0, &action, 1, 0);
+ cls_rule_init_catchall(&rule, 0);
+ ofproto_add_flow(br->ofproto, &rule, &action, 1);
}
}
hash_int(iface->dp_ifidx, 0));
}
- if (iface->cfg) {
- int64_t ofport = (iface->dp_ifidx >= 0
- ? odp_port_to_ofp_port(iface->dp_ifidx)
- : -1);
- ovsrec_interface_set_ofport(iface->cfg, &ofport, 1);
- }
+ iface_set_ofport(iface->cfg,
+ (iface->dp_ifidx >= 0
+ ? odp_port_to_ofp_port(iface->dp_ifidx)
+ : -1));
}
}
free(dpif_ports);
/* Track carrier going up and down on interfaces. */
while (!netdev_monitor_poll(port->monitor, &devname)) {
struct iface *iface;
- bool carrier;
iface = port_lookup_iface(port, devname);
- if (iface && !netdev_get_carrier(iface->netdev, &carrier)) {
+ if (iface) {
+ bool carrier = netdev_get_carrier(iface->netdev);
+
bond_link_status_update(iface, carrier);
port_update_bond_compat(port);
}
return vlan == port->vlan || port_trunks_vlan(port, vlan);
}
+static bool
+port_is_floodable(const struct port *port)
+{
+ int i;
+
+ for (i = 0; i < port->n_ifaces; i++) {
+ if (!ofproto_port_is_floodable(port->bridge->ofproto,
+ port->ifaces[i]->dp_ifidx)) {
+ return false;
+ }
+ }
+ return true;
+}
+
static size_t
compose_dsts(const struct bridge *br, const struct flow *flow, uint16_t vlan,
const struct port *in_port, const struct port *out_port,
/* XXX even better, define each VLAN as a datapath port group */
for (i = 0; i < br->n_ports; i++) {
struct port *port = br->ports[i];
- if (port != in_port && port_includes_vlan(port, vlan)
+ if (port != in_port
+ && port_is_floodable(port)
+ && port_includes_vlan(port, vlan)
&& !port->is_mirror_output_port
&& set_dst(dst, flow, in_port, port, tags)) {
mirrors |= port->dst_mirrors;
} else {
a = odp_actions_add(actions, ODPAT_SET_DL_TCI);
a->dl_tci.tci = htons(p->vlan & VLAN_VID_MASK);
- a->dl_tci.mask = htons(VLAN_VID_MASK);
+ a->dl_tci.tci |= htons(flow->dl_vlan_pcp << VLAN_PCP_SHIFT);
}
cur_vlan = p->vlan;
}
if (!shash_add_once(&new_ifaces, if_cfg->name, NULL)) {
VLOG_WARN("port %s: %s specified twice as port interface",
port->name, if_cfg->name);
+ iface_set_ofport(if_cfg, -1);
continue;
}
del = br->ports[port->port_idx] = br->ports[--br->n_ports];
del->port_idx = port->port_idx;
+ VLOG_INFO("destroyed port %s on bridge %s", port->name, br->name);
+
netdev_monitor_destroy(port->monitor);
free(port->ifaces);
bitmap_free(port->trunks);
}
}
+/* Sets the ofport column of 'if_cfg' to 'ofport'. */
+static void
+iface_set_ofport(const struct ovsrec_interface *if_cfg, int64_t ofport)
+{
+ if (if_cfg) {
+ ovsrec_interface_set_ofport(if_cfg, &ofport, 1);
+ }
+}
+
/* Adds the 'n' key-value pairs in 'keys' in 'values' to 'shash'.
*
* The value strings in '*shash' are taken directly from values[], not copied,