ovs-ofctl: Fix handling of unexpected replies in dump_stats_transaction().
authorBen Pfaff <blp@nicira.com>
Mon, 11 Jun 2012 18:15:31 +0000 (11:15 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 27 Jun 2012 21:29:02 +0000 (14:29 -0700)
dump_stats_transaction() ignored errors and other non-stats replies to
its request and would continue to wait forever.  This fixes the problem.

Signed-off-by: Ben Pfaff <blp@nicira.com>
utilities/ovs-ofctl.c

index 7413455..a2dfabf 100644 (file)
@@ -380,6 +380,7 @@ static void
 dump_stats_transaction(const char *vconn_name, struct ofpbuf *request)
 {
     ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
+    ovs_be16 stats_type = ((struct ofp_stats_msg *) request->data)->type;
     struct vconn *vconn;
     bool done = false;
 
@@ -392,12 +393,21 @@ dump_stats_transaction(const char *vconn_name, struct ofpbuf *request)
         run(vconn_recv_block(vconn, &reply), "OpenFlow packet receive failed");
         recv_xid = ((struct ofp_header *) reply->data)->xid;
         if (send_xid == recv_xid) {
-            struct ofp_stats_msg *osm;
+            const struct ofp_stats_msg *osm = reply->data;
+            const struct ofp_header *oh = reply->data;
 
             ofp_print(stdout, reply->data, reply->size, verbosity + 1);
 
-            osm = ofpbuf_at(reply, 0, sizeof *osm);
-            done = !osm || !(ntohs(osm->flags) & OFPSF_REPLY_MORE);
+            if (oh->type == OFPT_ERROR) {
+                done = true;
+            } else if (oh->type == OFPT10_STATS_REPLY
+                       && osm->type == stats_type) {
+                done = !(ntohs(osm->flags) & OFPSF_REPLY_MORE);
+            } else {
+                ovs_fatal(0, "received bad reply: %s",
+                          ofp_to_string(reply->data, reply->size,
+                                        verbosity + 1));
+            }
         } else {
             VLOG_DBG("received reply with xid %08"PRIx32" "
                      "!= expected %08"PRIx32, recv_xid, send_xid);