X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=vswitchd%2Fbridge.c;h=316ecc75ee25a1bf1e562efe4ad48d9ffe137843;hb=70dbc259b83796688dcef8593eff5f74f7e36aa1;hp=27d40a87519f252d3ac4f5525bf94195f9af77b8;hpb=acf60855126bcfa79ea22d7846af5f2efe26cd30;p=openvswitch diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 27d40a87..316ecc75 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -227,6 +227,8 @@ static void mirror_refresh_stats(struct mirror *); static void iface_configure_lacp(struct iface *, struct lacp_slave_settings *); static bool iface_create(struct bridge *, struct if_cfg *, int ofp_port); +static bool iface_is_internal(const struct ovsrec_interface *iface, + const struct ovsrec_bridge *br); static const char *iface_get_type(const struct ovsrec_interface *, const struct ovsrec_bridge *); static void iface_destroy(struct iface *); @@ -276,25 +278,27 @@ bridge_init_ofproto(const struct ovsrec_open_vswitch *cfg) shash_init(&iface_hints); - for (i = 0; i < cfg->n_bridges; i++) { - const struct ovsrec_bridge *br_cfg = cfg->bridges[i]; - int j; + if (cfg) { + for (i = 0; i < cfg->n_bridges; i++) { + const struct ovsrec_bridge *br_cfg = cfg->bridges[i]; + int j; - for (j = 0; j < br_cfg->n_ports; j++) { - struct ovsrec_port *port_cfg = br_cfg->ports[j]; - int k; + for (j = 0; j < br_cfg->n_ports; j++) { + struct ovsrec_port *port_cfg = br_cfg->ports[j]; + int k; - for (k = 0; k < port_cfg->n_interfaces; k++) { - struct ovsrec_interface *if_cfg = port_cfg->interfaces[k]; - struct iface_hint *iface_hint; + for (k = 0; k < port_cfg->n_interfaces; k++) { + struct ovsrec_interface *if_cfg = port_cfg->interfaces[k]; + struct iface_hint *iface_hint; - iface_hint = xmalloc(sizeof *iface_hint); - iface_hint->br_name = br_cfg->name; - iface_hint->br_type = br_cfg->datapath_type; - iface_hint->ofp_port = if_cfg->n_ofport_request ? - *if_cfg->ofport_request : OFPP_NONE; + iface_hint = xmalloc(sizeof *iface_hint); + iface_hint->br_name = br_cfg->name; + iface_hint->br_type = br_cfg->datapath_type; + iface_hint->ofp_port = if_cfg->n_ofport_request ? + *if_cfg->ofport_request : OFPP_NONE; - shash_add(&iface_hints, if_cfg->name, iface_hint); + shash_add(&iface_hints, if_cfg->name, iface_hint); + } } } } @@ -996,16 +1000,11 @@ port_configure_stp(const struct ofproto *ofproto, struct port *port, port_s->path_cost = strtoul(config_str, NULL, 10); } else { enum netdev_features current; + unsigned int mbps; - if (netdev_get_features(iface->netdev, ¤t, NULL, NULL, NULL)) { - /* Couldn't get speed, so assume 100Mb/s. */ - port_s->path_cost = 19; - } else { - unsigned int mbps; - - mbps = netdev_features_to_bps(current) / 1000000; - port_s->path_cost = stp_convert_speed_to_cost(mbps); - } + netdev_get_features(iface->netdev, ¤t, NULL, NULL, NULL); + mbps = netdev_features_to_bps(current, 100 * 1000 * 1000) / 1000000; + port_s->path_cost = stp_convert_speed_to_cost(mbps); } config_str = smap_get(&port->cfg->other_config, "stp-port-priority"); @@ -1350,7 +1349,8 @@ iface_do_create(const struct bridge *br, br->name, iface_cfg->name, *ofp_portp); } - if (port_cfg->vlan_mode && !strcmp(port_cfg->vlan_mode, "splinter")) { + if ((port_cfg->vlan_mode && !strcmp(port_cfg->vlan_mode, "splinter")) + || iface_is_internal(iface_cfg, br->cfg)) { netdev_turn_flags_on(netdev, NETDEV_UP, true); } @@ -1701,12 +1701,11 @@ iface_refresh_status(struct iface *iface) smap_destroy(&smap); error = netdev_get_features(iface->netdev, ¤t, NULL, NULL, NULL); - if (!error) { + bps = !error ? netdev_features_to_bps(current, 0) : 0; + if (bps) { ovsrec_interface_set_duplex(iface->cfg, netdev_features_is_full_duplex(current) ? "full" : "half"); - /* warning: uint64_t -> int64_t conversion */ - bps = netdev_features_to_bps(current); ovsrec_interface_set_link_speed(iface->cfg, &bps, 1); } else { @@ -2801,7 +2800,7 @@ bridge_configure_remotes(struct bridge *br, n_ocs++; } - ofproto_set_controllers(br->ofproto, ocs, n_ocs); + ofproto_set_controllers(br->ofproto, ocs, n_ocs, 0); free(ocs[0].target); /* From bridge_ofproto_controller_for_mgmt(). */ free(ocs); @@ -3139,20 +3138,32 @@ port_is_synthetic(const struct port *port) /* Interface functions. */ +static bool +iface_is_internal(const struct ovsrec_interface *iface, + const struct ovsrec_bridge *br) +{ + /* The local port and "internal" ports are always "internal". */ + return !strcmp(iface->type, "internal") || !strcmp(iface->name, br->name); +} + /* Returns the correct network device type for interface 'iface' in bridge * 'br'. */ static const char * iface_get_type(const struct ovsrec_interface *iface, const struct ovsrec_bridge *br) { - /* The local port always has type "internal" unless the bridge is of - * type "dummy". Other ports take their type from the database and - * default to "system" if none is specified. */ - if (!strcmp(iface->name, br->name)) { - return !strcmp(br->datapath_type, "dummy") ? "dummy" : "internal"; + const char *type; + + /* The local port always has type "internal". Other ports take + * their type from the database and default to "system" if none is + * specified. */ + if (iface_is_internal(iface, br)) { + type = "internal"; } else { - return iface->type[0] ? iface->type : "system"; + type = iface->type[0] ? iface->type : "system"; } + + return ofproto_port_open_type(br->datapath_type, type); } static void