X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=vswitchd%2Fbridge.c;h=45a14911f5c89bc9b1a7f0814331ef3ca77b77f8;hb=96be8de5951502c4d23f80529f4b8785aaf94f04;hp=f325afa6857d71a4ec3bddad10d34b5c4557bcbc;hpb=61c7584076dfb778697dcc132f5bcabdd42c9d9c;p=sliver-openvswitch.git diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index f325afa68..45a14911f 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc. +/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -165,6 +165,11 @@ static uint64_t connectivity_seqno = LLONG_MIN; #define IFACE_STATS_INTERVAL (5 * 1000) /* In milliseconds. */ static long long int iface_stats_timer = LLONG_MIN; +/* Set to true to allow experimental use of OpenFlow 1.4. + * This is false initially because OpenFlow 1.4 is not yet safe to use: it can + * abort due to unimplemented features. */ +static bool allow_of14; + /* In some datapaths, creating and destroying OpenFlow ports can be extremely * expensive. This can cause bridge_reconfigure() to take a long time during * which no other work can be done. To deal with this problem, we limit port @@ -176,6 +181,7 @@ static long long int iface_stats_timer = LLONG_MIN; #define OFP_PORT_ACTION_WINDOW 10 static void add_del_bridges(const struct ovsrec_open_vswitch *); +static void bridge_run__(void); static void bridge_create(const struct ovsrec_bridge *); static void bridge_destroy(struct bridge *); static struct bridge *bridge_lookup(const char *name); @@ -193,7 +199,6 @@ static void bridge_del_ports(struct bridge *, static void bridge_add_ports(struct bridge *, const struct shash *wanted_ports); -static void bridge_configure_flow_miss_model(const char *opt); static void bridge_configure_datapath_id(struct bridge *); static void bridge_configure_netflow(struct bridge *); static void bridge_configure_forward_bpdu(struct bridge *); @@ -247,11 +252,12 @@ static bool iface_is_internal(const struct ovsrec_interface *iface, static const char *iface_get_type(const struct ovsrec_interface *, const struct ovsrec_bridge *); static void iface_destroy(struct iface *); +static void iface_destroy__(struct iface *); static struct iface *iface_lookup(const struct bridge *, const char *name); static struct iface *iface_find(const char *name); static struct iface *iface_from_ofp_port(const struct bridge *, ofp_port_t ofp_port); -static void iface_set_mac(struct iface *); +static void iface_set_mac(const struct bridge *, const struct port *, struct iface *); static void iface_set_ofport(const struct ovsrec_interface *, ofp_port_t ofport); static void iface_clear_db_record(const struct ovsrec_interface *if_cfg); static void iface_configure_qos(struct iface *, const struct ovsrec_qos *); @@ -354,7 +360,6 @@ bridge_init(const char *remote) ovsdb_idl_omit_alert(idl, &ovsrec_port_col_status); ovsdb_idl_omit_alert(idl, &ovsrec_port_col_statistics); ovsdb_idl_omit(idl, &ovsrec_port_col_external_ids); - ovsdb_idl_omit(idl, &ovsrec_port_col_fake_bridge); ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_admin_state); ovsdb_idl_omit_alert(idl, &ovsrec_interface_col_duplex); @@ -426,6 +431,14 @@ bridge_exit(void) ovsdb_idl_destroy(idl); } +/* Enables use of OpenFlow 1.4. This is off by default because OpenFlow 1.4 is + * not yet safe to use: it can abort due to unimplemented features. */ +void +bridge_enable_of14(void) +{ + allow_of14 = true; +} + /* Looks at the list of managers in 'ovs_cfg' and extracts their remote IP * addresses and ports into '*managersp' and '*n_managersp'. The caller is * responsible for freeing '*managersp' (with free()). @@ -466,12 +479,12 @@ collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg, managers = xmalloc(sset_count(&targets) * sizeof *managers); SSET_FOR_EACH (target, &targets) { - struct sockaddr_in *sin = &managers[n_managers]; + struct sockaddr_storage ss; - if (stream_parse_target_with_default_port(target, - OVSDB_OLD_PORT, - sin)) { - n_managers++; + if (stream_parse_target_with_default_port(target, OVSDB_OLD_PORT, + &ss) + && ss.ss_family == AF_INET) { + managers[n_managers++] = *(struct sockaddr_in *) &ss; } } } @@ -492,15 +505,14 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) COVERAGE_INC(bridge_reconfigure); - ofproto_set_flow_eviction_threshold( - smap_get_int(&ovs_cfg->other_config, "flow-eviction-threshold", - OFPROTO_FLOW_EVICTION_THRESHOLD_DEFAULT)); + ofproto_set_flow_limit(smap_get_int(&ovs_cfg->other_config, "flow-limit", + OFPROTO_FLOW_LIMIT_DEFAULT)); + ofproto_set_max_idle(smap_get_int(&ovs_cfg->other_config, "max-idle", + OFPROTO_MAX_IDLE_DEFAULT)); ofproto_set_threads( - smap_get_int(&ovs_cfg->other_config, "n-handler-threads", 0)); - - bridge_configure_flow_miss_model(smap_get(&ovs_cfg->other_config, - "force-miss-model")); + smap_get_int(&ovs_cfg->other_config, "n-handler-threads", 0), + smap_get_int(&ovs_cfg->other_config, "n-revalidator-threads", 0)); /* Destroy "struct bridge"s, "struct port"s, and "struct iface"s according * to 'ovs_cfg', with only very minimal configuration otherwise. @@ -575,9 +587,10 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) port_configure(port); LIST_FOR_EACH (iface, port_elem, &port->ifaces) { + iface_set_ofport(iface->cfg, iface->ofp_port); iface_configure_cfm(iface); iface_configure_qos(iface, port->cfg->qos); - iface_set_mac(iface); + iface_set_mac(br, port, iface); ofproto_port_set_bfd(br->ofproto, iface->ofp_port, &iface->cfg->bfd); } @@ -601,6 +614,13 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg) } } free(managers); + + /* The ofproto-dpif provider does some final reconfiguration in its + * ->type_run() function. We have to call it before notifying the database + * client that reconfiguration is complete, otherwise there is a very + * narrow race window in which e.g. ofproto/trace will not recognize the + * new configuration (sometimes this causes unit test failures). */ + bridge_run__(); } /* Delete ofprotos which aren't configured or have the wrong type. Create @@ -648,6 +668,9 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) struct ofproto_port ofproto_port; struct ofproto_port_dump dump; + struct sset ofproto_ports; + struct port *port, *port_next; + /* List of "ofp_port"s to delete. We make a list instead of deleting them * right away because ofproto implementations aren't necessarily able to * iterate through a changing list of ports in an entirely robust way. */ @@ -657,11 +680,21 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) del = NULL; n = allocated = 0; + sset_init(&ofproto_ports); + /* Main task: Iterate over the ports in 'br->ofproto' and remove the ports + * that are not configured in the database. (This commonly happens when + * ports have been deleted, e.g. with "ovs-vsctl del-port".) + * + * Side tasks: Reconfigure the ports that are still in 'br'. Delete ports + * that have the wrong OpenFlow port number (and arrange to add them back + * with the correct OpenFlow port number). */ OFPROTO_PORT_FOR_EACH (&ofproto_port, &dump, br->ofproto) { ofp_port_t requested_ofp_port; struct iface *iface; + sset_add(&ofproto_ports, ofproto_port.name); + iface = iface_lookup(br, ofproto_port.name); if (!iface) { /* No such iface is configured, so we should delete this @@ -727,11 +760,37 @@ bridge_delete_or_reconfigure_ports(struct bridge *br) iface_destroy(iface); del = add_ofp_port(ofproto_port.ofp_port, del, &n, &allocated); } - for (i = 0; i < n; i++) { ofproto_port_del(br->ofproto, del[i]); } free(del); + + /* Iterate over this module's idea of interfaces in 'br'. Remove any ports + * that we didn't see when we iterated through the datapath, i.e. ports + * that disappeared underneath use. This is an unusual situation, but it + * can happen in some cases: + * + * - An admin runs a command like "ovs-dpctl del-port" (which is a bad + * idea but could happen). + * + * - The port represented a device that disappeared, e.g. a tuntap + * device destroyed via "tunctl -d", a physical Ethernet device + * whose module was just unloaded via "rmmod", or a virtual NIC for a + * VM whose VM was just terminated. */ + HMAP_FOR_EACH_SAFE (port, port_next, hmap_node, &br->ports) { + struct iface *iface, *iface_next; + + LIST_FOR_EACH_SAFE (iface, iface_next, port_elem, &port->ifaces) { + if (!sset_contains(&ofproto_ports, iface->name)) { + iface_destroy__(iface); + } + } + + if (list_is_empty(&port->ifaces)) { + port_destroy(port); + } + } + sset_destroy(&ofproto_ports); } static void @@ -820,15 +879,16 @@ port_configure(struct port *port) s.vlan_mode = PORT_VLAN_NATIVE_UNTAGGED; } else { /* This "can't happen" because ovsdb-server should prevent it. */ - VLOG_ERR("unknown VLAN mode %s", cfg->vlan_mode); + VLOG_WARN("port %s: unknown VLAN mode %s, falling " + "back to trunk mode", port->name, cfg->vlan_mode); s.vlan_mode = PORT_VLAN_TRUNK; } } else { if (s.vlan >= 0) { s.vlan_mode = PORT_VLAN_ACCESS; if (cfg->n_trunks) { - VLOG_ERR("port %s: ignoring trunks in favor of implicit vlan", - port->name); + VLOG_WARN("port %s: ignoring trunks in favor of implicit vlan", + port->name); } } else { s.vlan_mode = PORT_VLAN_TRUNK; @@ -870,22 +930,6 @@ port_configure(struct port *port) free(s.lacp_slaves); } -static void -bridge_configure_flow_miss_model(const char *opt) -{ - enum ofproto_flow_miss_model model = OFPROTO_HANDLE_MISS_AUTO; - - if (opt) { - if (strcmp(opt, "with-facets")) { - model = OFPROTO_HANDLE_MISS_WITH_FACETS; - } else if (strcmp(opt, "without-facets")) { - model = OFPROTO_HANDLE_MISS_WITHOUT_FACETS; - } - } - - ofproto_set_flow_miss_model(model); -} - /* Pick local port hardware address and datapath ID for 'br'. */ static void bridge_configure_datapath_id(struct bridge *br) @@ -925,11 +969,17 @@ bridge_configure_datapath_id(struct bridge *br) static uint32_t bridge_get_allowed_versions(struct bridge *br) { + uint32_t allowed_versions; + if (!br->cfg->n_protocols) return 0; - return ofputil_versions_from_strings(br->cfg->protocols, - br->cfg->n_protocols); + allowed_versions = ofputil_versions_from_strings(br->cfg->protocols, + br->cfg->n_protocols); + if (!allow_of14) { + allowed_versions &= ~(1u << OFP14_VERSION); + } + return allowed_versions; } /* Set NetFlow configuration on 'br'. */ @@ -1317,7 +1367,7 @@ bridge_configure_stp(struct bridge *br) } } - if (bitmap_scan(port_num_bitmap, 0, STP_MAX_PORTS) != STP_MAX_PORTS + if (bitmap_scan(port_num_bitmap, 1, 0, STP_MAX_PORTS) != STP_MAX_PORTS && port_num_counter) { VLOG_ERR("bridge %s: must manually configure all STP port " "IDs or none, disabling", br->name); @@ -1394,10 +1444,8 @@ iface_set_netdev_config(const struct ovsrec_interface *iface_cfg, return netdev_set_config(netdev, &iface_cfg->options); } -/* Opens a network device for 'if_cfg' and configures it. If '*ofp_portp' - * is OFPP_NONE, adds the network device to br->ofproto and stores the OpenFlow - * port number in '*ofp_portp'; otherwise leaves br->ofproto and '*ofp_portp' - * untouched. +/* Opens a network device for 'if_cfg' and configures it. Adds the network + * device to br->ofproto and stores the OpenFlow port number in '*ofp_portp'. * * If successful, returns 0 and stores the network device in '*netdevp'. On * failure, returns a positive errno value and stores NULL in '*netdevp'. */ @@ -1439,8 +1487,7 @@ iface_do_create(const struct bridge *br, VLOG_INFO("bridge %s: added interface %s on port %d", br->name, iface_cfg->name, *ofp_portp); - if ((port_cfg->vlan_mode && !strcmp(port_cfg->vlan_mode, "splinter")) - || iface_is_internal(iface_cfg, br->cfg)) { + if (port_cfg->vlan_mode && !strcmp(port_cfg->vlan_mode, "splinter")) { netdev_turn_flags_on(netdev, NETDEV_UP, NULL); } @@ -1473,7 +1520,6 @@ iface_create(struct bridge *br, const struct ovsrec_interface *iface_cfg, ovs_assert(!iface_lookup(br, iface_cfg->name)); error = iface_do_create(br, iface_cfg, port_cfg, &ofp_port, &netdev); if (error) { - iface_set_ofport(iface_cfg, OFPP_NONE); iface_clear_db_record(iface_cfg); return false; } @@ -1498,8 +1544,6 @@ iface_create(struct bridge *br, const struct ovsrec_interface *iface_cfg, hmap_insert(&br->ifaces, &iface->ofp_port_node, hash_ofp_port(ofp_port)); - iface_set_ofport(iface->cfg, ofp_port); - /* Populate initial status in database. */ iface_refresh_stats(iface); iface_refresh_status(iface); @@ -1565,31 +1609,15 @@ bridge_configure_mac_table(struct bridge *br) } static void -bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN], - struct iface **hw_addr_iface) +find_local_hw_addr(const struct bridge *br, uint8_t ea[ETH_ADDR_LEN], + const struct port *fake_br, struct iface **hw_addr_iface) { struct hmapx mirror_output_ports; - const char *hwaddr; struct port *port; bool found_addr = false; int error; int i; - *hw_addr_iface = NULL; - - /* Did the user request a particular MAC? */ - hwaddr = smap_get(&br->cfg->other_config, "hwaddr"); - if (hwaddr && eth_addr_from_string(hwaddr, ea)) { - if (eth_addr_is_multicast(ea)) { - VLOG_ERR("bridge %s: cannot set MAC address to multicast " - "address "ETH_ADDR_FMT, br->name, ETH_ADDR_ARGS(ea)); - } else if (eth_addr_is_zero(ea)) { - VLOG_ERR("bridge %s: cannot set MAC address to zero", br->name); - } else { - return; - } - } - /* Mirror output ports don't participate in picking the local hardware * address. ofproto can't help us find out whether a given port is a * mirror output because we haven't configured mirrors yet, so we need to @@ -1645,6 +1673,16 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN], continue; } + /* For fake bridges we only choose from ports with the same tag */ + if (fake_br && fake_br->cfg && fake_br->cfg->tag) { + if (!port->cfg->tag) { + continue; + } + if (*port->cfg->tag != *fake_br->cfg->tag) { + continue; + } + } + /* Grab MAC. */ error = netdev_get_etheraddr(iface->netdev, iface_ea); if (error) { @@ -1673,6 +1711,30 @@ bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN], hmapx_destroy(&mirror_output_ports); } +static void +bridge_pick_local_hw_addr(struct bridge *br, uint8_t ea[ETH_ADDR_LEN], + struct iface **hw_addr_iface) +{ + const char *hwaddr; + *hw_addr_iface = NULL; + + /* Did the user request a particular MAC? */ + hwaddr = smap_get(&br->cfg->other_config, "hwaddr"); + if (hwaddr && eth_addr_from_string(hwaddr, ea)) { + if (eth_addr_is_multicast(ea)) { + VLOG_ERR("bridge %s: cannot set MAC address to multicast " + "address "ETH_ADDR_FMT, br->name, ETH_ADDR_ARGS(ea)); + } else if (eth_addr_is_zero(ea)) { + VLOG_ERR("bridge %s: cannot set MAC address to zero", br->name); + } else { + return; + } + } + + /* Find a local hw address */ + find_local_hw_addr(br, ea, NULL, hw_addr_iface); +} + /* Choose and returns the datapath ID for bridge 'br' given that the bridge * Ethernet address is 'bridge_ea'. If 'bridge_ea' is the Ethernet address of * an interface on 'br', then that interface must be passed in as @@ -2252,13 +2314,32 @@ instant_stats_wait(void) } } +static void +bridge_run__(void) +{ + struct bridge *br; + struct sset types; + const char *type; + + /* Let each datapath type do the work that it needs to do. */ + sset_init(&types); + ofproto_enumerate_types(&types); + SSET_FOR_EACH (type, &types) { + ofproto_type_run(type); + } + sset_destroy(&types); + + /* Let each bridge do the work that it needs to do. */ + HMAP_FOR_EACH (br, node, &all_bridges) { + ofproto_run(br->ofproto); + } +} + void bridge_run(void) { static struct ovsrec_open_vswitch null_cfg; const struct ovsrec_open_vswitch *cfg; - struct sset types; - const char *type; bool vlan_splinters_changed; struct bridge *br; @@ -2301,18 +2382,7 @@ bridge_run(void) "flow-restore-wait", false)); } - /* Let each datapath type do the work that it needs to do. */ - sset_init(&types); - ofproto_enumerate_types(&types); - SSET_FOR_EACH (type, &types) { - ofproto_type_run(type); - } - sset_destroy(&types); - - /* Let each bridge do the work that it needs to do. */ - HMAP_FOR_EACH (br, node, &all_bridges) { - ofproto_run(br->ofproto); - } + bridge_run__(); /* 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 @@ -2832,7 +2902,8 @@ bridge_configure_local_iface_netdev(struct bridge *br, /* If there's no local interface or no IP address, give up. */ local_iface = iface_from_ofp_port(br, OFPP_LOCAL); - if (!local_iface || !c->local_ip || !inet_aton(c->local_ip, &ip)) { + if (!local_iface || !c->local_ip + || !inet_pton(AF_INET, c->local_ip, &ip)) { return; } @@ -2842,7 +2913,7 @@ bridge_configure_local_iface_netdev(struct bridge *br, /* Configure the IP address and netmask. */ if (!c->local_netmask - || !inet_aton(c->local_netmask, &mask) + || !inet_pton(AF_INET, c->local_netmask, &mask) || !mask.s_addr) { mask.s_addr = guess_netmask(ip.s_addr); } @@ -2853,7 +2924,7 @@ bridge_configure_local_iface_netdev(struct bridge *br, /* Configure the default gateway. */ if (c->local_gateway - && inet_aton(c->local_gateway, &gateway) + && inet_pton(AF_INET, c->local_gateway, &gateway) && gateway.s_addr) { if (!netdev_add_router(netdev, gateway)) { VLOG_INFO("bridge %s: configured gateway "IP_FMT, @@ -3114,8 +3185,6 @@ bridge_configure_dp_desc(struct bridge *br) /* Port functions. */ -static void iface_destroy__(struct iface *); - static struct port * port_create(struct bridge *br, const struct ovsrec_port *cfg) { @@ -3477,21 +3546,33 @@ iface_from_ofp_port(const struct bridge *br, ofp_port_t ofp_port) /* Set Ethernet address of 'iface', if one is specified in the configuration * file. */ static void -iface_set_mac(struct iface *iface) +iface_set_mac(const struct bridge *br, const struct port *port, struct iface *iface) { - uint8_t ea[ETH_ADDR_LEN]; + uint8_t ea[ETH_ADDR_LEN], *mac = NULL; + struct iface *hw_addr_iface; + + if (strcmp(iface->type, "internal")) { + return; + } + + if (iface->cfg->mac && eth_addr_from_string(iface->cfg->mac, ea)) { + mac = ea; + } else if (port->cfg->fake_bridge) { + /* Fake bridge and no MAC set in the configuration. Pick a local one. */ + find_local_hw_addr(br, ea, port, &hw_addr_iface); + mac = ea; + } - if (!strcmp(iface->type, "internal") - && iface->cfg->mac && eth_addr_from_string(iface->cfg->mac, ea)) { + if (mac) { if (iface->ofp_port == OFPP_LOCAL) { VLOG_ERR("interface %s: ignoring mac in Interface record " "(use Bridge record to set local port's mac)", iface->name); - } else if (eth_addr_is_multicast(ea)) { + } else if (eth_addr_is_multicast(mac)) { VLOG_ERR("interface %s: cannot set MAC to multicast address", iface->name); } else { - int error = netdev_set_etheraddr(iface->netdev, ea); + int error = netdev_set_etheraddr(iface->netdev, mac); if (error) { VLOG_ERR("interface %s: setting MAC failed (%s)", iface->name, ovs_strerror(error)); @@ -3519,6 +3600,7 @@ static void iface_clear_db_record(const struct ovsrec_interface *if_cfg) { if (!ovsdb_idl_row_is_synthetic(&if_cfg->header_)) { + iface_set_ofport(if_cfg, OFPP_NONE); ovsrec_interface_set_status(if_cfg, NULL); ovsrec_interface_set_admin_state(if_cfg, NULL); ovsrec_interface_set_duplex(if_cfg, NULL); @@ -3606,8 +3688,8 @@ iface_configure_qos(struct iface *iface, const struct ovsrec_qos *qos) } if (iface->ofp_port != OFPP_NONE) { - const struct ofproto_port_queue *port_queues = queues_buf.data; - size_t n_queues = queues_buf.size / sizeof *port_queues; + const struct ofproto_port_queue *port_queues = ofpbuf_data(&queues_buf); + size_t n_queues = ofpbuf_size(&queues_buf) / sizeof *port_queues; ofproto_port_set_queues(iface->port->bridge->ofproto, iface->ofp_port, port_queues, n_queues); @@ -4067,7 +4149,7 @@ collect_splinter_vlans(const struct ovsrec_open_vswitch *ovs_cfg) sset_destroy(&splinter_ifaces); - if (bitmap_scan(splinter_vlans, 0, 4096) >= 4096) { + if (bitmap_scan(splinter_vlans, 1, 0, 4096) >= 4096) { free(splinter_vlans); return NULL; }