From 5767fb1117e54b287def73b82875bc8d847bbdb0 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 20 Apr 2011 13:03:45 -0700 Subject: [PATCH] ofproto: Consistently use netdev's name instead of ofp_phy_port name. There are at least two ways to get an ofport's name: from the netdev using netdev_get_name() or from the ofp_phy_port's 'name' member. Some code used one, some used the other. This switches all relevant code to use only netdev_get_name(), because the 'name' member in ofp_phy_port is fixed-length and thus a long name could be truncated. This isn't a problem under Linux since the maximum length of a network device's name under Linux is the same as the field width in ofp_phy_port. --- ofproto/ofproto.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index f4b64f881..0223ed0b7 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1376,7 +1376,7 @@ int ofproto_port_del(struct ofproto *ofproto, uint16_t odp_port) { struct ofport *ofport = get_port(ofproto, odp_port); - const char *name = ofport ? ofport->opp.name : ""; + const char *name = ofport ? netdev_get_name(ofport->netdev) : ""; int error; error = dpif_port_del(ofproto->dpif, odp_port); @@ -1384,8 +1384,8 @@ ofproto_port_del(struct ofproto *ofproto, uint16_t odp_port) VLOG_ERR("%s: failed to remove port %"PRIu16" (%s) interface (%s)", dpif_name(ofproto->dpif), odp_port, name, strerror(error)); } else if (ofport) { - /* 'name' is ofport->opp.name and update_port() is going to destroy - * 'ofport'. Just in case update_port() refers to 'name' after it + /* 'name' is the netdev's name and update_port() is going to close the + * netdev. Just in case update_port() refers to 'name' after it * destroys 'ofport', make a copy of it around the update_port() * call. */ char *devname = xstrdup(name); @@ -1503,7 +1503,7 @@ reinit_ports(struct ofproto *p) shash_init(&devnames); HMAP_FOR_EACH (ofport, hmap_node, &p->ports) { - shash_add_once (&devnames, ofport->opp.name, NULL); + shash_add_once (&devnames, netdev_get_name(ofport->netdev), NULL); } DPIF_PORT_FOR_EACH (&dpif_port, &dump, p->dpif) { shash_add_once (&devnames, dpif_port.name, NULL); @@ -1618,7 +1618,7 @@ send_port_status(struct ofproto *p, const struct ofport *ofport, static void ofport_install(struct ofproto *p, struct ofport *ofport) { - const char *netdev_name = ofport->opp.name; + const char *netdev_name = netdev_get_name(ofport->netdev); netdev_monitor_add(p->netdev_monitor, ofport->netdev); hmap_insert(&p->ports, &ofport->hmap_node, hash_int(ofport->odp_port, 0)); @@ -1634,7 +1634,8 @@ ofport_remove(struct ofproto *p, struct ofport *ofport) netdev_monitor_remove(p->netdev_monitor, ofport->netdev); hmap_remove(&p->ports, &ofport->hmap_node); shash_delete(&p->port_by_name, - shash_find(&p->port_by_name, ofport->opp.name)); + shash_find(&p->port_by_name, + netdev_get_name(ofport->netdev))); if (p->sflow) { ofproto_sflow_del_port(p->sflow, ofport->odp_port); } -- 2.47.0