From: Ben Pfaff Date: Tue, 24 Apr 2012 22:59:42 +0000 (-0700) Subject: vswitchd: Refactor iface_refresh_type() into iface_get_type(). X-Git-Tag: sliver-openvswitch-0.1-1~48 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=b54441b366ff133079f6adc3fc9a0f456119af46;p=sliver-openvswitch.git vswitchd: Refactor iface_refresh_type() into iface_get_type(). The calculation that this function does will need to be used in a context where no "struct iface" is available in an upcoming commit. Signed-off-by: Ben Pfaff --- diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 204972083..208396b32 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -228,7 +228,8 @@ static void mirror_refresh_stats(struct mirror *); static void iface_configure_lacp(struct iface *, struct lacp_slave_settings *); static void iface_create(struct bridge *, struct if_cfg *, int ofp_port); -static void iface_refresh_type(struct iface *); +static const char *iface_get_type(const struct ovsrec_interface *, + const struct ovsrec_bridge *); 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); @@ -1255,7 +1256,7 @@ iface_create(struct bridge *br, struct if_cfg *if_cfg, int ofp_port) hmap_insert(&br->iface_by_name, &iface->name_node, hash_string(iface->name, 0)); list_push_back(&port->ifaces, &iface->port_elem); - iface_refresh_type(iface); + iface->type = iface_get_type(iface->cfg, br->cfg); if (ofp_port >= 0) { iface_set_ofp_port(iface, ofp_port); } @@ -2494,6 +2495,8 @@ bridge_add_del_ports(struct bridge *br, } } + /* Update iface->cfg and iface->type in interfaces that still exist. + * Add new interfaces to creation queue. */ SHASH_FOR_EACH (port_node, &new_ports) { const struct ovsrec_port *port = port_node->data; size_t i; @@ -2504,7 +2507,7 @@ bridge_add_del_ports(struct bridge *br, if (iface) { iface->cfg = cfg; - iface_refresh_type(iface); + iface->type = iface_get_type(cfg, br->cfg); } else { bridge_queue_if_cfg(br, cfg, port); } @@ -3060,15 +3063,17 @@ port_is_synthetic(const struct port *port) /* Interface functions. */ -static void -iface_refresh_type(struct iface *iface) -{ - /* Determine interface type. The local port always has type - * "internal". Other ports take their type from the database and - * default to "system" if none is specified. */ - iface->type = (!strcmp(iface->name, iface->port->bridge->name) ? "internal" - : iface->cfg->type[0] ? iface->cfg->type - : "system"); +/* 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". Other ports take their type + * from the database and default to "system" if none is specified. */ + return (!strcmp(iface->name, br->name) ? "internal" + : iface->type[0] ? iface->type + : "system"); } static void