From 0a54c658c635b0f0618072e06164652ad5f13f23 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 27 Dec 2010 12:46:48 -0800 Subject: [PATCH] ovs-dpctl: Reimplement get_port_number() using dpif_port_query_by_name(). 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. Acked-by: Jesse Gross --- utilities/ovs-dpctl.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index b12ceb75..ff31fb8e 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 -- 2.30.2