ofproto: Check ofproto_port_query_by_name() return value when adding port.
authorBen Pfaff <blp@nicira.com>
Tue, 19 Mar 2013 20:30:33 +0000 (13:30 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 11 Nov 2013 16:42:08 +0000 (08:42 -0800)
Otherwise, if the port add succeeds but the query that looks up the port
number fails, then ofproto_port_add() would return zero as the OpenFlow
port number and ignore the error.

Reported-by: Guolin Yang <gyang@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
AUTHORS
ofproto/ofproto.c

diff --git a/AUTHORS b/AUTHORS
index ac7886b..8154e40 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -154,6 +154,7 @@ Giuseppe de Candia      giuseppe.decandia@gmail.com
 Gordon Good             ggood@nicira.com
 Greg Dahlman            gdahlman@hotmail.com
 Gregor Schaffrath       grsch@net.t-labs.tu-berlin.de
+Guolin Yang             gyang@vmware.com
 Hassan Khan             hassan.khan@seecs.edu.pk
 Hector Oron             hector.oron@gmail.com
 Henrik Amren            henrik@nicira.com
index d565b19..2ccbcee 100644 (file)
@@ -1772,12 +1772,18 @@ ofproto_port_add(struct ofproto *ofproto, struct netdev *netdev,
         update_port(ofproto, netdev_name);
     }
     if (ofp_portp) {
-        struct ofproto_port ofproto_port;
-
-        ofproto_port_query_by_name(ofproto, netdev_get_name(netdev),
-                                   &ofproto_port);
-        *ofp_portp = error ? OFPP_NONE : ofproto_port.ofp_port;
-        ofproto_port_destroy(&ofproto_port);
+        *ofp_portp = OFPP_NONE;
+        if (!error) {
+            struct ofproto_port ofproto_port;
+
+            error = ofproto_port_query_by_name(ofproto,
+                                               netdev_get_name(netdev),
+                                               &ofproto_port);
+            if (!error) {
+                *ofp_portp = ofproto_port.ofp_port;
+                ofproto_port_destroy(&ofproto_port);
+            }
+        }
     }
     return error;
 }