X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=vswitchd%2Fbridge.c;h=e66313f639a549cf3f6dc0f0fcac1654cd18cfa5;hb=78661a5ed344f6f4c3d45d64662a74947b31435d;hp=ef30cc3694a8647c0f9bd293d76e66b6cb7b5db0;hpb=786880a5509c6dd38a7ab592e1e2853208a2c606;p=sliver-openvswitch.git diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index ef30cc369..e66313f63 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -33,7 +33,6 @@ #include "bitmap.h" #include "coverage.h" #include "dirs.h" -#include "dpif.h" #include "dynamic-string.h" #include "flow.h" #include "hash.h" @@ -41,11 +40,12 @@ #include "list.h" #include "mac-learning.h" #include "netdev.h" -#include "odp-util.h" +#include "xflow-util.h" #include "ofp-print.h" #include "ofpbuf.h" #include "ofproto/netflow.h" #include "ofproto/ofproto.h" +#include "ovsdb-data.h" #include "packets.h" #include "poll-loop.h" #include "port-array.h" @@ -62,15 +62,16 @@ #include "vconn.h" #include "vswitchd/vswitch-idl.h" #include "xenserver.h" +#include "vlog.h" +#include "xfif.h" #include "xtoxll.h" #include "sflow_api.h" -#define THIS_MODULE VLM_bridge -#include "vlog.h" +VLOG_DEFINE_THIS_MODULE(bridge) struct dst { uint16_t vlan; - uint16_t dp_ifidx; + uint16_t xf_ifidx; }; struct iface { @@ -83,7 +84,7 @@ struct iface { /* These members are valid only after bridge_reconfigure() causes them to * be initialized. */ - int dp_ifidx; /* Index within kernel datapath. */ + int xf_ifidx; /* Index within kernel datapath. */ struct netdev *netdev; /* Network device. */ bool enabled; /* May be chosen for flows? */ const struct ovsrec_interface *cfg; @@ -104,6 +105,7 @@ struct mirror { struct bridge *bridge; size_t idx; char *name; + struct uuid uuid; /* UUID of this "mirror" record in database. */ /* Selection criteria. */ struct shash src_ports; /* Name is port name; data is always NULL. */ @@ -161,7 +163,7 @@ struct bridge { struct ofproto *ofproto; /* OpenFlow switch. */ /* Kernel datapath information. */ - struct dpif *dpif; /* Datapath. */ + struct xfif *xfif; /* Datapath. */ struct port_array ifaces; /* Indexed by kernel datapath port number. */ /* Bridge ports. */ @@ -197,13 +199,10 @@ static struct bridge *bridge_lookup(const char *name); static unixctl_cb_func bridge_unixctl_dump_flows; static unixctl_cb_func bridge_unixctl_reconnect; static int bridge_run_one(struct bridge *); -static size_t bridge_get_controllers(const struct ovsrec_open_vswitch *ovs_cfg, - const struct bridge *br, +static size_t bridge_get_controllers(const struct bridge *br, struct ovsrec_controller ***controllersp); -static void bridge_reconfigure_one(const struct ovsrec_open_vswitch *, - struct bridge *); -static void bridge_reconfigure_remotes(const struct ovsrec_open_vswitch *, - struct bridge *, +static void bridge_reconfigure_one(struct bridge *); +static void bridge_reconfigure_remotes(struct bridge *, const struct sockaddr_in *managers, size_t n_managers); static void bridge_get_all_ifaces(const struct bridge *, struct shash *ifaces); @@ -233,13 +232,13 @@ static void port_del_ifaces(struct port *, const struct ovsrec_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 struct port *port_from_xf_ifidx(const struct bridge *, + uint16_t xf_ifidx); static void port_update_bond_compat(struct port *); static void port_update_vlan_compat(struct port *); static void port_update_bonding(struct port *); -static struct mirror *mirror_create(struct bridge *, const char *name); +static void mirror_create(struct bridge *, struct ovsrec_mirror *); static void mirror_destroy(struct mirror *); static void mirror_reconfigure(struct bridge *); static void mirror_reconfigure_one(struct mirror *, struct ovsrec_mirror *); @@ -249,8 +248,8 @@ static struct iface *iface_create(struct port *port, const struct ovsrec_interface *if_cfg); static void iface_destroy(struct iface *); static struct iface *iface_lookup(const struct bridge *, const char *name); -static struct iface *iface_from_dp_ifidx(const struct bridge *, - uint16_t dp_ifidx); +static struct iface *iface_from_xf_ifidx(const struct bridge *, + uint16_t xf_ifidx); static bool iface_is_internal(const struct bridge *, const char *name); static void iface_set_mac(struct iface *); static void iface_update_qos(struct iface *, const struct ovsrec_qos *); @@ -285,7 +284,7 @@ bridge_configure_once(const struct ovsrec_open_vswitch *cfg) { static bool already_configured_once; struct svec bridge_names; - struct svec dpif_names, dpif_types; + struct svec xfif_names, xfif_types; size_t i; /* Only do this once per ovs-vswitchd run. */ @@ -303,61 +302,48 @@ bridge_configure_once(const struct ovsrec_open_vswitch *cfg) } svec_sort(&bridge_names); - /* Iterate over all system dpifs and delete any of them that do not appear + /* Iterate over all system xfifs and delete any of them that do not appear * in 'cfg'. */ - svec_init(&dpif_names); - svec_init(&dpif_types); - dp_enumerate_types(&dpif_types); - for (i = 0; i < dpif_types.n; i++) { - struct dpif *dpif; + svec_init(&xfif_names); + svec_init(&xfif_types); + xf_enumerate_types(&xfif_types); + for (i = 0; i < xfif_types.n; i++) { + struct xfif *xfif; int retval; size_t j; - dp_enumerate_names(dpif_types.names[i], &dpif_names); + xf_enumerate_names(xfif_types.names[i], &xfif_names); - /* For each dpif... */ - for (j = 0; j < dpif_names.n; j++) { - retval = dpif_open(dpif_names.names[j], dpif_types.names[i], &dpif); + /* For each xfif... */ + for (j = 0; j < xfif_names.n; j++) { + retval = xfif_open(xfif_names.names[j], xfif_types.names[i], &xfif); if (!retval) { struct svec all_names; size_t k; /* ...check whether any of its names is in 'bridge_names'. */ svec_init(&all_names); - dpif_get_all_names(dpif, &all_names); + xfif_get_all_names(xfif, &all_names); for (k = 0; k < all_names.n; k++) { if (svec_contains(&bridge_names, all_names.names[k])) { goto found; } } - /* No. Delete the dpif. */ - dpif_delete(dpif); + /* No. Delete the xfif. */ + xfif_delete(xfif); found: svec_destroy(&all_names); - dpif_close(dpif); + xfif_close(xfif); } } } svec_destroy(&bridge_names); - svec_destroy(&dpif_names); - svec_destroy(&dpif_types); + svec_destroy(&xfif_names); + svec_destroy(&xfif_types); } -#ifdef HAVE_OPENSSL -static void -bridge_configure_ssl(const struct ovsrec_ssl *ssl) -{ - /* XXX SSL should be configurable on a per-bridge basis. */ - if (ssl) { - stream_ssl_set_private_key_file(ssl->private_key); - stream_ssl_set_certificate_file(ssl->certificate); - stream_ssl_set_ca_cert_file(ssl->ca_cert, ssl->bootstrap_ca_cert); - } -} -#endif - /* Attempt to create the network device 'iface_name' through the netdev * library. */ static int @@ -387,7 +373,6 @@ set_up_iface(const struct ovsrec_interface *iface_cfg, struct iface *iface, } netdev_options.args = &options; netdev_options.ethertype = NETDEV_ETH_TYPE_NONE; - error = netdev_open(&netdev_options, &iface->netdev); if (iface->netdev) { @@ -439,17 +424,17 @@ check_iface_netdev(struct bridge *br OVS_UNUSED, struct iface *iface, } static bool -check_iface_dp_ifidx(struct bridge *br, struct iface *iface, +check_iface_xf_ifidx(struct bridge *br, struct iface *iface, void *aux OVS_UNUSED) { - if (iface->dp_ifidx >= 0) { + if (iface->xf_ifidx >= 0) { VLOG_DBG("%s has interface %s on port %d", - dpif_name(br->dpif), - iface->name, iface->dp_ifidx); + xfif_name(br->xfif), + iface->name, iface->xf_ifidx); return true; } else { VLOG_ERR("%s interface not in %s, dropping", - iface->name, dpif_name(br->dpif)); + iface->name, xfif_name(br->xfif)); return false; } } @@ -465,7 +450,7 @@ set_iface_properties(struct bridge *br OVS_UNUSED, struct iface *iface, /* Set MAC address of internal interfaces other than the local * interface. */ - if (iface->dp_ifidx != ODPP_LOCAL + if (iface->xf_ifidx != XFLOWP_LOCAL && iface_is_internal(br, iface->name)) { iface_set_mac(iface); } @@ -597,14 +582,9 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) shash_destroy(&old_br); shash_destroy(&new_br); -#ifdef HAVE_OPENSSL - /* Configure SSL. */ - bridge_configure_ssl(ovs_cfg->ssl); -#endif - /* Reconfigure all bridges. */ LIST_FOR_EACH (br, struct bridge, node, &all_bridges) { - bridge_reconfigure_one(ovs_cfg, br); + bridge_reconfigure_one(br); } /* Add and delete ports on all datapaths. @@ -613,41 +593,41 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) * that port already belongs to a different datapath, so we must do all * port deletions before any port additions. */ LIST_FOR_EACH (br, struct bridge, node, &all_bridges) { - struct odp_port *dpif_ports; - size_t n_dpif_ports; + struct xflow_port *xfif_ports; + size_t n_xfif_ports; struct shash want_ifaces; - dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports); + xfif_port_list(br->xfif, &xfif_ports, &n_xfif_ports); bridge_get_all_ifaces(br, &want_ifaces); - for (i = 0; i < n_dpif_ports; i++) { - const struct odp_port *p = &dpif_ports[i]; + for (i = 0; i < n_xfif_ports; i++) { + const struct xflow_port *p = &xfif_ports[i]; if (!shash_find(&want_ifaces, p->devname) && strcmp(p->devname, br->name)) { - int retval = dpif_port_del(br->dpif, p->port); + int retval = xfif_port_del(br->xfif, p->port); if (retval) { VLOG_ERR("failed to remove %s interface from %s: %s", - p->devname, dpif_name(br->dpif), + p->devname, xfif_name(br->xfif), strerror(retval)); } } } shash_destroy(&want_ifaces); - free(dpif_ports); + free(xfif_ports); } LIST_FOR_EACH (br, struct bridge, node, &all_bridges) { - struct odp_port *dpif_ports; - size_t n_dpif_ports; + struct xflow_port *xfif_ports; + size_t n_xfif_ports; struct shash cur_ifaces, want_ifaces; struct shash_node *node; /* Get the set of interfaces currently in this datapath. */ - dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports); + xfif_port_list(br->xfif, &xfif_ports, &n_xfif_ports); shash_init(&cur_ifaces); - for (i = 0; i < n_dpif_ports; i++) { - const char *name = dpif_ports[i].devname; + for (i = 0; i < n_xfif_ports; i++) { + const char *name = xfif_ports[i].devname; shash_add_once(&cur_ifaces, name, NULL); } - free(dpif_ports); + free(xfif_ports); /* Get the set of interfaces we want on this datapath. */ bridge_get_all_ifaces(br, &want_ifaces); @@ -668,15 +648,15 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) /* Add to datapath. */ internal = iface_is_internal(br, if_name); - error = dpif_port_add(br->dpif, if_name, - internal ? ODP_PORT_INTERNAL : 0, NULL); + error = xfif_port_add(br->xfif, if_name, + internal ? XFLOW_PORT_INTERNAL : 0, NULL); if (error == EFBIG) { VLOG_ERR("ran out of valid port numbers on %s", - dpif_name(br->dpif)); + xfif_name(br->xfif)); break; } else if (error) { VLOG_ERR("failed to add %s interface to %s: %s", - if_name, dpif_name(br->dpif), strerror(error)); + if_name, xfif_name(br->xfif), strerror(error)); } } } @@ -694,7 +674,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) bridge_fetch_dp_ifaces(br); iterate_and_prune_ifaces(br, check_iface_netdev, NULL); - iterate_and_prune_ifaces(br, check_iface_dp_ifidx, NULL); + iterate_and_prune_ifaces(br, check_iface_xf_ifidx, NULL); /* Pick local port hardware address, datapath ID. */ bridge_pick_local_hw_addr(br, ea, &hw_addr_iface); @@ -723,7 +703,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) memset(&opts, 0, sizeof opts); - dpif_get_netflow_ids(br->dpif, &opts.engine_type, &opts.engine_id); + xfif_get_netflow_ids(br->xfif, &opts.engine_type, &opts.engine_id); if (nf_cfg->engine_type) { opts.engine_type = *nf_cfg->engine_type; } @@ -797,7 +777,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) oso.agent_device = sflow_cfg->agent; oso.control_ip = NULL; - n_controllers = bridge_get_controllers(ovs_cfg, br, &controllers); + n_controllers = bridge_get_controllers(br, &controllers); for (i = 0; i < n_controllers; i++) { if (controllers[i]->local_ip) { oso.control_ip = controllers[i]->local_ip; @@ -814,13 +794,13 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) /* Update the controller and related settings. It would be more * straightforward to call this from bridge_reconfigure_one(), but we * can't do it there for two reasons. First, and most importantly, at - * that point we don't know the dp_ifidx of any interfaces that have + * that point we don't know the xf_ifidx of any interfaces that have * been added to the bridge (because we haven't actually added them to * the datapath). Second, at that point we haven't set the datapath ID * yet; when a controller is configured, resetting the datapath ID will * immediately disconnect from the controller, so it's better to set * the datapath ID before the controller. */ - bridge_reconfigure_remotes(ovs_cfg, br, managers, n_managers); + bridge_reconfigure_remotes(br, managers, n_managers); } LIST_FOR_EACH (br, struct bridge, node, &all_bridges) { for (i = 0; i < br->n_ports; i++) { @@ -930,7 +910,7 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN], /* The local port doesn't count (since we're trying to choose its * MAC address anyway). */ - if (iface->dp_ifidx == ODPP_LOCAL) { + if (iface->xf_ifidx == XFLOWP_LOCAL) { continue; } @@ -1107,7 +1087,10 @@ iface_refresh_stats(struct iface *iface) void bridge_run(void) { + const struct ovsrec_open_vswitch *cfg; + bool datapath_destroyed; + bool database_changed; struct bridge *br; /* Let each bridge do the work that it needs to do. */ @@ -1123,8 +1106,9 @@ bridge_run(void) } /* (Re)configure if necessary. */ - if (ovsdb_idl_run(idl) || datapath_destroyed) { - const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(idl); + database_changed = ovsdb_idl_run(idl); + cfg = ovsrec_open_vswitch_first(idl); + if (database_changed || datapath_destroyed) { if (cfg) { struct ovsdb_idl_txn *txn = ovsdb_idl_txn_create(idl); @@ -1143,6 +1127,18 @@ bridge_run(void) } } +#ifdef HAVE_OPENSSL + /* Re-configure SSL. We do this on every trip through the main loop, + * instead of just when the database changes, because the contents of the + * key and certificate files can change without the database changing. */ + if (cfg && cfg->ssl) { + const struct ovsrec_ssl *ssl = cfg->ssl; + + stream_ssl_set_key_and_cert(ssl->private_key, ssl->certificate); + stream_ssl_set_ca_cert_file(ssl->ca_cert, ssl->bootstrap_ca_cert); + } +#endif + /* Refresh interface stats if necessary. */ if (time_msec() >= iface_stats_timer) { struct ovsdb_idl_txn *txn; @@ -1175,7 +1171,7 @@ bridge_wait(void) LIST_FOR_EACH (br, struct bridge, node, &all_bridges) { ofproto_wait(br->ofproto); - if (ofproto_has_controller(br->ofproto)) { + if (ofproto_has_primary_controller(br->ofproto)) { continue; } @@ -1192,11 +1188,11 @@ static void bridge_flush(struct bridge *br) { COVERAGE_INC(bridge_flush); - br->flush = true; + ofproto_revalidate_all(br->ofproto); mac_learning_flush(br->ml); } -/* Returns the 'br' interface for the ODPP_LOCAL port, or null if 'br' has no +/* Returns the 'br' interface for the XFLOWP_LOCAL port, or null if 'br' has no * such interface. */ static struct iface * bridge_get_local_iface(struct bridge *br) @@ -1207,7 +1203,7 @@ bridge_get_local_iface(struct bridge *br) struct port *port = br->ports[i]; for (j = 0; j < port->n_ifaces; j++) { struct iface *iface = port->ifaces[j]; - if (iface->dp_ifidx == ODPP_LOCAL) { + if (iface->xf_ifidx == XFLOWP_LOCAL) { return iface; } } @@ -1237,7 +1233,7 @@ bridge_unixctl_fdb_show(struct unixctl_conn *conn, continue; } ds_put_format(&ds, "%5d %4d "ETH_ADDR_FMT" %3d\n", - br->ports[e->port]->ifaces[0]->dp_ifidx, + br->ports[e->port]->ifaces[0]->xf_ifidx, e->vlan, ETH_ADDR_ARGS(e->mac), mac_entry_age(e)); } unixctl_command_reply(conn, 200, ds_cstr(&ds)); @@ -1254,21 +1250,21 @@ bridge_create(const struct ovsrec_bridge *br_cfg) assert(!bridge_lookup(br_cfg->name)); br = xzalloc(sizeof *br); - error = dpif_create_and_open(br_cfg->name, br_cfg->datapath_type, - &br->dpif); + error = xfif_create_and_open(br_cfg->name, br_cfg->datapath_type, + &br->xfif); if (error) { free(br); return NULL; } - dpif_flow_flush(br->dpif); + xfif_flow_flush(br->xfif); error = ofproto_create(br_cfg->name, br_cfg->datapath_type, &bridge_ofhooks, br, &br->ofproto); if (error) { VLOG_ERR("failed to create switch %s: %s", br_cfg->name, strerror(error)); - dpif_delete(br->dpif); - dpif_close(br->dpif); + xfif_delete(br->xfif); + xfif_close(br->xfif); free(br); return NULL; } @@ -1283,11 +1279,9 @@ bridge_create(const struct ovsrec_bridge *br_cfg) shash_init(&br->port_by_name); shash_init(&br->iface_by_name); - br->flush = false; - list_push_back(&all_bridges, &br->node); - VLOG_INFO("created bridge %s on %s", br->name, dpif_name(br->dpif)); + VLOG_INFO("created bridge %s on %s", br->name, xfif_name(br->xfif)); return br; } @@ -1302,12 +1296,12 @@ bridge_destroy(struct bridge *br) port_destroy(br->ports[br->n_ports - 1]); } list_remove(&br->node); - error = dpif_delete(br->dpif); + error = xfif_delete(br->xfif); if (error && error != ENOENT) { VLOG_ERR("failed to delete %s: %s", - dpif_name(br->dpif), strerror(error)); + xfif_name(br->xfif), strerror(error)); } - dpif_close(br->dpif); + xfif_close(br->xfif); ofproto_destroy(br->ofproto); mac_learning_destroy(br->ml); port_array_destroy(&br->ifaces); @@ -1380,37 +1374,20 @@ bridge_unixctl_reconnect(struct unixctl_conn *conn, static int bridge_run_one(struct bridge *br) { - int error; - - error = ofproto_run1(br->ofproto); - if (error) { - return error; - } - - mac_learning_run(br->ml, ofproto_get_revalidate_set(br->ofproto)); + ofproto_revalidate(br->ofproto, mac_learning_run(br->ml)); bond_run(br); - - error = ofproto_run2(br->ofproto, br->flush); - br->flush = false; - - return error; + return ofproto_run(br->ofproto); } static size_t -bridge_get_controllers(const struct ovsrec_open_vswitch *ovs_cfg, - const struct bridge *br, +bridge_get_controllers(const struct bridge *br, struct ovsrec_controller ***controllersp) { struct ovsrec_controller **controllers; size_t n_controllers; - if (br->cfg->n_controller) { - controllers = br->cfg->controller; - n_controllers = br->cfg->n_controller; - } else { - controllers = ovs_cfg->controller; - n_controllers = ovs_cfg->n_controller; - } + controllers = br->cfg->controller; + n_controllers = br->cfg->n_controller; if (n_controllers == 1 && !strcmp(controllers[0]->target, "none")) { controllers = NULL; @@ -1424,13 +1401,12 @@ bridge_get_controllers(const struct ovsrec_open_vswitch *ovs_cfg, } static void -bridge_reconfigure_one(const struct ovsrec_open_vswitch *ovs_cfg, - struct bridge *br) +bridge_reconfigure_one(struct bridge *br) { struct shash old_ports, new_ports; - struct svec listeners, old_listeners; struct svec snoops, old_snoops; struct shash_node *node; + enum ofproto_fail_mode fail_mode; size_t i; /* Collect old ports. */ @@ -1453,11 +1429,11 @@ bridge_reconfigure_one(const struct ovsrec_open_vswitch *ovs_cfg, * user didn't specify one. * * XXX perhaps we should synthesize a port ourselves in this case. */ - if (bridge_get_controllers(ovs_cfg, br, NULL)) { + if (bridge_get_controllers(br, NULL)) { char local_name[IF_NAMESIZE]; int error; - error = dpif_port_get_name(br->dpif, ODPP_LOCAL, + error = xfif_port_get_name(br->xfif, XFLOWP_LOCAL, local_name, sizeof local_name); if (!error && !shash_find(&new_ports, local_name)) { VLOG_WARN("bridge %s: controller specified but no local port " @@ -1499,22 +1475,21 @@ bridge_reconfigure_one(const struct ovsrec_open_vswitch *ovs_cfg, shash_destroy(&old_ports); shash_destroy(&new_ports); + /* Set the fail-mode */ + fail_mode = !br->cfg->fail_mode + || !strcmp(br->cfg->fail_mode, "standalone") + ? OFPROTO_FAIL_STANDALONE + : OFPROTO_FAIL_SECURE; + if (ofproto_get_fail_mode(br->ofproto) != fail_mode + && !ofproto_has_primary_controller(br->ofproto)) { + ofproto_flush_flows(br->ofproto); + } + ofproto_set_fail_mode(br->ofproto, fail_mode); + /* Delete all flows if we're switching from connected to standalone or vice * versa. (XXX Should we delete all flows if we are switching from one * controller to another?) */ - /* Configure OpenFlow management listener. */ - svec_init(&listeners); - svec_add_nocopy(&listeners, xasprintf("punix:%s/%s.mgmt", - ovs_rundir, br->name)); - svec_init(&old_listeners); - ofproto_get_listeners(br->ofproto, &old_listeners); - if (!svec_equal(&listeners, &old_listeners)) { - ofproto_set_listeners(br->ofproto, &listeners); - } - svec_destroy(&listeners); - svec_destroy(&old_listeners); - /* Configure OpenFlow controller connection snooping. */ svec_init(&snoops); svec_add_nocopy(&snoops, xasprintf("punix:%s/%s.snoop", @@ -1530,107 +1505,156 @@ bridge_reconfigure_one(const struct ovsrec_open_vswitch *ovs_cfg, mirror_reconfigure(br); } +/* Initializes 'oc' appropriately as a management service controller for + * 'br'. + * + * The caller must free oc->target when it is no longer needed. */ +static void +bridge_ofproto_controller_for_mgmt(const struct bridge *br, + struct ofproto_controller *oc) +{ + oc->target = xasprintf("punix:%s/%s.mgmt", ovs_rundir, br->name); + oc->max_backoff = 0; + oc->probe_interval = 60; + oc->band = OFPROTO_OUT_OF_BAND; + oc->accept_re = NULL; + oc->update_resolv_conf = false; + oc->rate_limit = 0; + oc->burst_limit = 0; +} + +/* Converts ovsrec_controller 'c' into an ofproto_controller in 'oc'. */ +static void +bridge_ofproto_controller_from_ovsrec(const struct ovsrec_controller *c, + struct ofproto_controller *oc) +{ + oc->target = c->target; + oc->max_backoff = c->max_backoff ? *c->max_backoff / 1000 : 8; + oc->probe_interval = c->inactivity_probe ? *c->inactivity_probe / 1000 : 5; + oc->band = (!c->connection_mode || !strcmp(c->connection_mode, "in-band") + ? OFPROTO_IN_BAND : OFPROTO_OUT_OF_BAND); + oc->accept_re = c->discover_accept_regex; + oc->update_resolv_conf = c->discover_update_resolv_conf; + oc->rate_limit = c->controller_rate_limit ? *c->controller_rate_limit : 0; + oc->burst_limit = (c->controller_burst_limit + ? *c->controller_burst_limit : 0); +} + +/* Configures the IP stack for 'br''s local interface properly according to the + * configuration in 'c'. */ +static void +bridge_configure_local_iface_netdev(struct bridge *br, + struct ovsrec_controller *c) +{ + struct netdev *netdev; + struct in_addr mask, gateway; + + struct iface *local_iface; + struct in_addr ip; + + /* Controller discovery does its own TCP/IP configuration later. */ + if (strcmp(c->target, "discover")) { + return; + } + + /* If there's no local interface or no IP address, give up. */ + local_iface = bridge_get_local_iface(br); + if (!local_iface || !c->local_ip || !inet_aton(c->local_ip, &ip)) { + return; + } + + /* Bring up the local interface. */ + netdev = local_iface->netdev; + netdev_turn_flags_on(netdev, NETDEV_UP, true); + + /* Configure the IP address and netmask. */ + if (!c->local_netmask + || !inet_aton(c->local_netmask, &mask) + || !mask.s_addr) { + mask.s_addr = guess_netmask(ip.s_addr); + } + if (!netdev_set_in4(netdev, ip, mask)) { + VLOG_INFO("bridge %s: configured IP address "IP_FMT", netmask "IP_FMT, + br->name, IP_ARGS(&ip.s_addr), IP_ARGS(&mask.s_addr)); + } + + /* Configure the default gateway. */ + if (c->local_gateway + && inet_aton(c->local_gateway, &gateway) + && gateway.s_addr) { + if (!netdev_add_router(netdev, gateway)) { + VLOG_INFO("bridge %s: configured gateway "IP_FMT, + br->name, IP_ARGS(&gateway.s_addr)); + } + } +} + static void -bridge_reconfigure_remotes(const struct ovsrec_open_vswitch *ovs_cfg, - struct bridge *br, +bridge_reconfigure_remotes(struct bridge *br, const struct sockaddr_in *managers, size_t n_managers) { struct ovsrec_controller **controllers; size_t n_controllers; + bool had_primary; + + struct ofproto_controller *ocs; + size_t n_ocs; + size_t i; 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); + + ocs = xmalloc((n_controllers + 1) * sizeof *ocs); + n_ocs = 0; + + bridge_ofproto_controller_for_mgmt(br, &ocs[n_ocs++]); + for (i = 0; i < n_controllers; i++) { + struct ovsrec_controller *c = controllers[i]; + + if (!strncmp(c->target, "punix:", 6) + || !strncmp(c->target, "unix:", 5)) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); + + /* Prevent remote ovsdb-server users from accessing arbitrary Unix + * domain sockets and overwriting arbitrary local files. */ + VLOG_ERR_RL(&rl, "%s: not adding Unix domain socket controller " + "\"%s\" due to possibility for remote exploit", + br->name, c->target); + continue; + } + + bridge_configure_local_iface_netdev(br, c); + bridge_ofproto_controller_from_ovsrec(c, &ocs[n_ocs++]); + } - n_controllers = bridge_get_controllers(ovs_cfg, br, &controllers); - if (ofproto_has_controller(br->ofproto) != (n_controllers != 0)) { + ofproto_set_controllers(br->ofproto, ocs, n_ocs); + free(ocs[0].target); /* From bridge_ofproto_controller_for_mgmt(). */ + free(ocs); + + if (had_primary != ofproto_has_primary_controller(br->ofproto)) { ofproto_flush_flows(br->ofproto); } - if (!n_controllers) { + /* If there are no controllers and the bridge is in standalone + * mode, set up a flow that matches every packet and directs + * them to OFPP_NORMAL (which goes to us). Otherwise, the + * switch is in secure mode and we won't pass any traffic until + * a controller has been defined and it tells us to do so. */ + if (!n_controllers + && ofproto_get_fail_mode(br->ofproto) == OFPROTO_FAIL_STANDALONE) { union ofp_action action; flow_t flow; - /* Clear out controllers. */ - ofproto_set_controllers(br->ofproto, NULL, 0); - - /* Set up a flow that matches every packet and directs them to - * OFPP_NORMAL (which goes to us). */ 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); - } else { - struct ofproto_controller *ocs; - size_t i; - - ocs = xmalloc(n_controllers * sizeof *ocs); - for (i = 0; i < n_controllers; i++) { - struct ovsrec_controller *c = controllers[i]; - struct ofproto_controller *oc = &ocs[i]; - - if (strcmp(c->target, "discover")) { - struct iface *local_iface; - struct in_addr ip; - - local_iface = bridge_get_local_iface(br); - if (local_iface && c->local_ip - && inet_aton(c->local_ip, &ip)) { - struct netdev *netdev = local_iface->netdev; - struct in_addr mask, gateway; - - if (!c->local_netmask - || !inet_aton(c->local_netmask, &mask)) { - mask.s_addr = 0; - } - if (!c->local_gateway - || !inet_aton(c->local_gateway, &gateway)) { - gateway.s_addr = 0; - } - - netdev_turn_flags_on(netdev, NETDEV_UP, true); - if (!mask.s_addr) { - mask.s_addr = guess_netmask(ip.s_addr); - } - if (!netdev_set_in4(netdev, ip, mask)) { - VLOG_INFO("bridge %s: configured IP address "IP_FMT", " - "netmask "IP_FMT, - br->name, IP_ARGS(&ip.s_addr), - IP_ARGS(&mask.s_addr)); - } - - if (gateway.s_addr) { - if (!netdev_add_router(netdev, gateway)) { - VLOG_INFO("bridge %s: configured gateway "IP_FMT, - br->name, IP_ARGS(&gateway.s_addr)); - } - } - } - } - - oc->target = c->target; - oc->max_backoff = c->max_backoff ? *c->max_backoff / 1000 : 8; - oc->probe_interval = (c->inactivity_probe - ? *c->inactivity_probe / 1000 : 5); - oc->fail = (!c->fail_mode - || !strcmp(c->fail_mode, "standalone") - || !strcmp(c->fail_mode, "open") - ? OFPROTO_FAIL_STANDALONE - : OFPROTO_FAIL_SECURE); - oc->band = (!c->connection_mode - || !strcmp(c->connection_mode, "in-band") - ? OFPROTO_IN_BAND - : OFPROTO_OUT_OF_BAND); - oc->accept_re = c->discover_accept_regex; - oc->update_resolv_conf = c->discover_update_resolv_conf; - oc->rate_limit = (c->controller_rate_limit - ? *c->controller_rate_limit : 0); - oc->burst_limit = (c->controller_burst_limit - ? *c->controller_burst_limit : 0); - } - ofproto_set_controllers(br->ofproto, ocs, n_controllers); - free(ocs); + flow.wildcards = OVSFW_ALL; + ofproto_add_flow(br->ofproto, &flow, &action, 1, 0); } } @@ -1655,16 +1679,16 @@ bridge_get_all_ifaces(const struct bridge *br, struct shash *ifaces) /* For robustness, in case the administrator moves around datapath ports behind * our back, we re-check all the datapath port numbers here. * - * This function will set the 'dp_ifidx' members of interfaces that have + * This function will set the 'xf_ifidx' members of interfaces that have * disappeared to -1, so only call this function from a context where those * 'struct iface's will be removed from the bridge. Otherwise, the -1 - * 'dp_ifidx'es will cause trouble later when we try to send them to the + * 'xf_ifidx'es will cause trouble later when we try to send them to the * datapath, which doesn't support UINT16_MAX+1 ports. */ static void bridge_fetch_dp_ifaces(struct bridge *br) { - struct odp_port *dpif_ports; - size_t n_dpif_ports; + struct xflow_port *xfif_ports; + size_t n_xfif_ports; size_t i, j; /* Reset all interface numbers. */ @@ -1672,36 +1696,36 @@ bridge_fetch_dp_ifaces(struct bridge *br) struct port *port = br->ports[i]; for (j = 0; j < port->n_ifaces; j++) { struct iface *iface = port->ifaces[j]; - iface->dp_ifidx = -1; + iface->xf_ifidx = -1; } } port_array_clear(&br->ifaces); - dpif_port_list(br->dpif, &dpif_ports, &n_dpif_ports); - for (i = 0; i < n_dpif_ports; i++) { - struct odp_port *p = &dpif_ports[i]; + xfif_port_list(br->xfif, &xfif_ports, &n_xfif_ports); + for (i = 0; i < n_xfif_ports; i++) { + struct xflow_port *p = &xfif_ports[i]; struct iface *iface = iface_lookup(br, p->devname); if (iface) { - if (iface->dp_ifidx >= 0) { + if (iface->xf_ifidx >= 0) { VLOG_WARN("%s reported interface %s twice", - dpif_name(br->dpif), p->devname); - } else if (iface_from_dp_ifidx(br, p->port)) { + xfif_name(br->xfif), p->devname); + } else if (iface_from_xf_ifidx(br, p->port)) { VLOG_WARN("%s reported interface %"PRIu16" twice", - dpif_name(br->dpif), p->port); + xfif_name(br->xfif), p->port); } else { port_array_set(&br->ifaces, p->port, iface); - iface->dp_ifidx = p->port; + iface->xf_ifidx = p->port; } if (iface->cfg) { - int64_t ofport = (iface->dp_ifidx >= 0 - ? odp_port_to_ofp_port(iface->dp_ifidx) + int64_t ofport = (iface->xf_ifidx >= 0 + ? xflow_port_to_ofp_port(iface->xf_ifidx) : -1); ovsrec_interface_set_ofport(iface->cfg, &ofport, 1); } } } - free(dpif_ports); + free(xfif_ports); } /* Bridge packet processing functions. */ @@ -1750,7 +1774,7 @@ bond_choose_iface(const struct port *port) static bool choose_output_iface(const struct port *port, const uint8_t *dl_src, - uint16_t *dp_ifidx, tag_type *tags) + uint16_t *xf_ifidx, tag_type *tags) { struct iface *iface; @@ -1774,7 +1798,7 @@ choose_output_iface(const struct port *port, const uint8_t *dl_src, *tags |= e->iface_tag; iface = port->ifaces[e->iface_idx]; } - *dp_ifidx = iface->dp_ifidx; + *xf_ifidx = iface->xf_ifidx; *tags |= iface->tag; /* Currently only used for bonding. */ return true; } @@ -1977,7 +2001,7 @@ set_dst(struct dst *p, const flow_t *flow, p->vlan = (out_port->vlan >= 0 ? OFP_VLAN_NONE : in_port->vlan >= 0 ? in_port->vlan : ntohs(flow->dl_vlan)); - return choose_output_iface(out_port, flow->dl_src, &p->dp_ifidx, tags); + return choose_output_iface(out_port, flow->dl_src, &p->xf_ifidx, tags); } static void @@ -2038,7 +2062,7 @@ dst_is_duplicate(const struct dst *dsts, size_t n_dsts, { size_t i; for (i = 0; i < n_dsts; i++) { - if (dsts[i].vlan == test->vlan && dsts[i].dp_ifidx == test->dp_ifidx) { + if (dsts[i].vlan == test->vlan && dsts[i].xf_ifidx == test->xf_ifidx) { return true; } } @@ -2068,7 +2092,7 @@ compose_dsts(const struct bridge *br, const flow_t *flow, uint16_t vlan, size_t i; if (out_port == FLOOD_PORT) { - /* XXX use ODP_FLOOD if no vlans or bonding. */ + /* XXX use XFLOW_FLOOD if no vlans or bonding. */ /* 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]; @@ -2081,7 +2105,7 @@ compose_dsts(const struct bridge *br, const flow_t *flow, uint16_t vlan, } *nf_output_iface = NF_OUT_FLOOD; } else if (out_port && set_dst(dst, flow, in_port, out_port, tags)) { - *nf_output_iface = dst->dp_ifidx; + *nf_output_iface = dst->xf_ifidx; mirrors |= out_port->dst_mirrors; dst++; } @@ -2139,7 +2163,7 @@ static void OVS_UNUSED print_dsts(const struct dst *dsts, size_t n) { for (; n--; dsts++) { - printf(">p%"PRIu16, dsts->dp_ifidx); + printf(">p%"PRIu16, dsts->xf_ifidx); if (dsts->vlan != OFP_VLAN_NONE) { printf("v%"PRIu16, dsts->vlan); } @@ -2149,7 +2173,7 @@ print_dsts(const struct dst *dsts, size_t n) static void compose_actions(struct bridge *br, const flow_t *flow, uint16_t vlan, const struct port *in_port, const struct port *out_port, - tag_type *tags, struct odp_actions *actions, + tag_type *tags, struct xflow_actions *actions, uint16_t *nf_output_iface) { struct dst dsts[DP_MAX_PORTS * (MAX_MIRRORS + 1)]; @@ -2162,18 +2186,19 @@ compose_actions(struct bridge *br, const flow_t *flow, uint16_t vlan, cur_vlan = ntohs(flow->dl_vlan); for (p = dsts; p < &dsts[n_dsts]; p++) { - union odp_action *a; + union xflow_action *a; if (p->vlan != cur_vlan) { if (p->vlan == OFP_VLAN_NONE) { - odp_actions_add(actions, ODPAT_STRIP_VLAN); + xflow_actions_add(actions, XFLOWAT_STRIP_VLAN); } else { - a = odp_actions_add(actions, ODPAT_SET_VLAN_VID); - a->vlan_vid.vlan_vid = htons(p->vlan); + a = xflow_actions_add(actions, XFLOWAT_SET_DL_TCI); + a->dl_tci.tci = htons(p->vlan & VLAN_VID_MASK); + a->dl_tci.mask = htons(VLAN_VID_MASK); } cur_vlan = p->vlan; } - a = odp_actions_add(actions, ODPAT_OUTPUT); - a->output.port = p->dp_ifidx; + a = xflow_actions_add(actions, XFLOWAT_OUTPUT); + a->output.port = p->xf_ifidx; } } @@ -2293,7 +2318,7 @@ is_admissible(struct bridge *br, const flow_t *flow, bool have_packet, int vlan; /* Find the interface and port structure for the received packet. */ - in_iface = iface_from_dp_ifidx(br, flow->in_port); + in_iface = iface_from_xf_ifidx(br, ofp_port_to_xflow_port(flow->in_port)); if (!in_iface) { /* No interface? Something fishy... */ if (have_packet) { @@ -2375,7 +2400,7 @@ is_admissible(struct bridge *br, const flow_t *flow, bool have_packet, * not at all, if 'packet' was NULL. */ static bool process_flow(struct bridge *br, const flow_t *flow, - const struct ofpbuf *packet, struct odp_actions *actions, + const struct ofpbuf *packet, struct xflow_actions *actions, tag_type *tags, uint16_t *nf_output_iface) { struct port *in_port; @@ -2435,7 +2460,7 @@ bridge_port_changed_ofhook_cb(enum ofp_port_reason reason, struct iface *iface; struct port *port; - iface = iface_from_dp_ifidx(br, ofp_port_to_odp_port(opp->port_no)); + iface = iface_from_xf_ifidx(br, ofp_port_to_xflow_port(opp->port_no)); if (!iface) { return; } @@ -2463,41 +2488,46 @@ bridge_port_changed_ofhook_cb(enum ofp_port_reason reason, static bool bridge_normal_ofhook_cb(const flow_t *flow, const struct ofpbuf *packet, - struct odp_actions *actions, tag_type *tags, + struct xflow_actions *actions, tag_type *tags, uint16_t *nf_output_iface, void *br_) { struct bridge *br = br_; COVERAGE_INC(bridge_process_flow); + return process_flow(br, flow, packet, actions, tags, nf_output_iface); } static void -bridge_account_flow_ofhook_cb(const flow_t *flow, - const union odp_action *actions, +bridge_account_flow_ofhook_cb(const flow_t *flow, tag_type tags, + const union xflow_action *actions, size_t n_actions, unsigned long long int n_bytes, void *br_) { struct bridge *br = br_; - const union odp_action *a; + const union xflow_action *a; struct port *in_port; - tag_type tags = 0; + tag_type dummy = 0; int vlan; - /* Feed information from the active flows back into the learning table - * to ensure that table is always in sync with what is actually flowing - * through the datapath. */ - if (is_admissible(br, flow, false, &tags, &vlan, &in_port)) { + /* Feed information from the active flows back into the learning table to + * ensure that table is always in sync with what is actually flowing + * through the datapath. + * + * We test that 'tags' is nonzero to ensure that only flows that include an + * OFPP_NORMAL action are used for learning. This works because + * bridge_normal_ofhook_cb() always sets a nonzero tag value. */ + if (tags && is_admissible(br, flow, false, &dummy, &vlan, &in_port)) { update_learning_table(br, flow, vlan, in_port); } + /* Account for bond slave utilization. */ if (!br->has_bonded_ports) { return; } - for (a = actions; a < &actions[n_actions]; a++) { - if (a->type == ODPAT_OUTPUT) { - struct port *out_port = port_from_dp_ifidx(br, a->output.port); + if (a->type == XFLOWAT_OUTPUT) { + struct port *out_port = port_from_xf_ifidx(br, a->output.port); if (out_port && out_port->n_ifaces >= 2) { struct bond_entry *e = lookup_bond_entry(out_port, flow->dl_src); @@ -2850,13 +2880,13 @@ bond_send_learning_packets(struct port *port) error = n_packets = n_errors = 0; LIST_FOR_EACH (e, struct mac_entry, lru_node, &br->ml->lrus) { union ofp_action actions[2], *a; - uint16_t dp_ifidx; + uint16_t xf_ifidx; tag_type tags = 0; flow_t flow; int retval; if (e->port == port->port_idx - || !choose_output_iface(port, e->mac, &dp_ifidx, &tags)) { + || !choose_output_iface(port, e->mac, &xf_ifidx, &tags)) { continue; } @@ -2871,14 +2901,14 @@ bond_send_learning_packets(struct port *port) } a->output.type = htons(OFPAT_OUTPUT); a->output.len = htons(sizeof *a); - a->output.port = htons(odp_port_to_ofp_port(dp_ifidx)); + a->output.port = htons(xflow_port_to_ofp_port(xf_ifidx)); a++; /* Send packet. */ n_packets++; compose_benign_packet(&packet, "Open vSwitch Bond Failover", 0xf177, e->mac); - flow_extract(&packet, 0, ODPP_NONE, &flow); + flow_extract(&packet, 0, OFPP_NONE, &flow); retval = ofproto_send_packet(br->ofproto, &flow, actions, a - actions, &packet); if (retval) { @@ -3001,12 +3031,12 @@ bond_unixctl_show(struct unixctl_conn *conn, /* MACs. */ LIST_FOR_EACH (me, struct mac_entry, lru_node, &port->bridge->ml->lrus) { - uint16_t dp_ifidx; + uint16_t xf_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) + && choose_output_iface(port, me->mac, &xf_ifidx, &tags) + && xf_ifidx == iface->xf_ifidx) { ds_put_format(&ds, "\t\t"ETH_ADDR_FMT"\n", ETH_ADDR_ARGS(me->mac)); @@ -3423,9 +3453,9 @@ port_destroy(struct port *port) } static struct port * -port_from_dp_ifidx(const struct bridge *br, uint16_t dp_ifidx) +port_from_xf_ifidx(const struct bridge *br, uint16_t xf_ifidx) { - struct iface *iface = iface_from_dp_ifidx(br, dp_ifidx); + struct iface *iface = iface_from_xf_ifidx(br, xf_ifidx); return iface ? iface->port : NULL; } @@ -3601,7 +3631,7 @@ iface_create(struct port *port, const struct ovsrec_interface *if_cfg) iface->port = port; iface->port_ifidx = port->n_ifaces; iface->name = xstrdup(name); - iface->dp_ifidx = -1; + iface->xf_ifidx = -1; iface->tag = tag_create_random(); iface->delay_expires = LLONG_MAX; iface->netdev = NULL; @@ -3650,8 +3680,8 @@ iface_destroy(struct iface *iface) shash_find_and_delete_assert(&br->iface_by_name, iface->name); - if (iface->dp_ifidx >= 0) { - port_array_set(&br->ifaces, iface->dp_ifidx, NULL); + if (iface->xf_ifidx >= 0) { + port_array_set(&br->ifaces, iface->xf_ifidx, NULL); } del = port->ifaces[iface->port_ifidx] = port->ifaces[--port->n_ifaces]; @@ -3679,14 +3709,14 @@ iface_lookup(const struct bridge *br, const char *name) } static struct iface * -iface_from_dp_ifidx(const struct bridge *br, uint16_t dp_ifidx) +iface_from_xf_ifidx(const struct bridge *br, uint16_t xf_ifidx) { - return port_array_get(&br->ifaces, dp_ifidx); + return port_array_get(&br->ifaces, xf_ifidx); } /* Returns true if 'iface' is the name of an "internal" interface on bridge * 'br', that is, an interface that is entirely simulated within the datapath. - * The local port (ODPP_LOCAL) is always an internal interface. Other local + * The local port (XFLOWP_LOCAL) is always an internal interface. Other local * interfaces are created by setting "iface..internal = true". * * In addition, we have a kluge-y feature that creates an internal port with @@ -3727,7 +3757,7 @@ iface_set_mac(struct iface *iface) if (eth_addr_is_multicast(ea)) { VLOG_ERR("interface %s: cannot set MAC to multicast address", iface->name); - } else if (iface->dp_ifidx == ODPP_LOCAL) { + } else if (iface->xf_ifidx == XFLOWP_LOCAL) { VLOG_ERR("ignoring iface.%s.mac; use bridge.%s.mac instead", iface->name, iface->name); } else { @@ -3815,50 +3845,51 @@ iface_update_qos(struct iface *iface, const struct ovsrec_qos *qos) /* Port mirroring. */ +static struct mirror * +mirror_find_by_uuid(struct bridge *br, const struct uuid *uuid) +{ + int i; + + for (i = 0; i < MAX_MIRRORS; i++) { + struct mirror *m = br->mirrors[i]; + if (m && uuid_equals(uuid, &m->uuid)) { + return m; + } + } + return NULL; +} + static void mirror_reconfigure(struct bridge *br) { - struct shash old_mirrors, new_mirrors; - struct shash_node *node; unsigned long *rspan_vlans; int i; - /* Collect old mirrors. */ - shash_init(&old_mirrors); + /* Get rid of deleted mirrors. */ for (i = 0; i < MAX_MIRRORS; i++) { - if (br->mirrors[i]) { - shash_add(&old_mirrors, br->mirrors[i]->name, br->mirrors[i]); + struct mirror *m = br->mirrors[i]; + if (m) { + const struct ovsdb_datum *mc; + union ovsdb_atom atom; + + mc = ovsrec_bridge_get_mirrors(br->cfg, OVSDB_TYPE_UUID); + atom.uuid = br->mirrors[i]->uuid; + if (ovsdb_datum_find_key(mc, &atom, OVSDB_TYPE_UUID) == UINT_MAX) { + mirror_destroy(m); + } } } - /* Collect new mirrors. */ - shash_init(&new_mirrors); + /* Add new mirrors and reconfigure existing ones. */ for (i = 0; i < br->cfg->n_mirrors; i++) { struct ovsrec_mirror *cfg = br->cfg->mirrors[i]; - if (!shash_add_once(&new_mirrors, cfg->name, cfg)) { - VLOG_WARN("bridge %s: %s specified twice as mirror", - br->name, cfg->name); - } - } - - /* Get rid of deleted mirrors and add new mirrors. */ - SHASH_FOR_EACH (node, &old_mirrors) { - if (!shash_find(&new_mirrors, node->name)) { - mirror_destroy(node->data); - } - } - SHASH_FOR_EACH (node, &new_mirrors) { - struct mirror *mirror = shash_find_data(&old_mirrors, node->name); - if (!mirror) { - mirror = mirror_create(br, node->name); - if (!mirror) { - break; - } + struct mirror *m = mirror_find_by_uuid(br, &cfg->header_.uuid); + if (m) { + mirror_reconfigure_one(m, cfg); + } else { + mirror_create(br, cfg); } - mirror_reconfigure_one(mirror, node->data); } - shash_destroy(&old_mirrors); - shash_destroy(&new_mirrors); /* Update port reserved status. */ for (i = 0; i < br->n_ports; i++) { @@ -3893,8 +3924,8 @@ mirror_reconfigure(struct bridge *br) } } -static struct mirror * -mirror_create(struct bridge *br, const char *name) +static void +mirror_create(struct bridge *br, struct ovsrec_mirror *cfg) { struct mirror *m; size_t i; @@ -3902,21 +3933,21 @@ mirror_create(struct bridge *br, const char *name) for (i = 0; ; i++) { if (i >= MAX_MIRRORS) { VLOG_WARN("bridge %s: maximum of %d port mirrors reached, " - "cannot create %s", br->name, MAX_MIRRORS, name); - return NULL; + "cannot create %s", br->name, MAX_MIRRORS, cfg->name); + return; } if (!br->mirrors[i]) { break; } } - VLOG_INFO("created port mirror %s on bridge %s", name, br->name); + VLOG_INFO("created port mirror %s on bridge %s", cfg->name, br->name); bridge_flush(br); br->mirrors[i] = m = xzalloc(sizeof *m); m->bridge = br; m->idx = i; - m->name = xstrdup(name); + m->name = xstrdup(cfg->name); shash_init(&m->src_ports); shash_init(&m->dst_ports); m->vlans = NULL; @@ -3924,7 +3955,7 @@ mirror_create(struct bridge *br, const char *name) m->out_vlan = -1; m->out_port = NULL; - return m; + mirror_reconfigure_one(m, cfg); } static void @@ -4026,6 +4057,12 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg) int *vlans; size_t i; + /* Set name. */ + if (strcmp(cfg->name, m->name)) { + free(m->name); + m->name = xstrdup(cfg->name); + } + /* Get output port. */ if (cfg->output_port) { out_port = port_lookup(m->bridge, cfg->output_port->name);