[ovs-dev] [netlink flows v2 02/12] ovs-dpctl: Reimplement get_port_number() using dpif_port_query_by_name().

Ben Pfaff blp at nicira.com
Tue Dec 28 22:32:57 UTC 2010


Presumably this function was written to iterate all of the ports because
at some point we didn't have a direct way to do this, but now
dpif_port_query_by_name() is the obvious way to do it.
---
 utilities/ovs-dpctl.c |   22 ++++++++--------------
 1 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index 8f2a2bc..0f36bfe 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -300,21 +300,15 @@ do_add_if(int argc OVS_UNUSED, char *argv[])
 static bool
 get_port_number(struct dpif *dpif, const char *name, uint16_t *port)
 {
-    struct odp_port *ports;
-    size_t n_ports;
-    size_t i;
+    struct odp_port odp_port;
 
-    query_ports(dpif, &ports, &n_ports);
-    for (i = 0; i < n_ports; i++) {
-        if (!strcmp(name, ports[i].devname)) {
-            *port = ports[i].port;
-            free(ports);
-            return true;
-        }
+    if (!dpif_port_query_by_name(dpif, name, &odp_port)) {
+        *port = odp_port.port;
+        return true;
+    } else {
+        ovs_error(0, "no port named %s", name);
+        return false;
     }
-    free(ports);
-    ovs_error(0, "no port named %s", name);
-    return false;
 }
 
 static void
-- 
1.7.1





More information about the dev mailing list