[ovs-dev] [ofp-print 14/18] ofp-print: Print vendor errors.

Ben Pfaff blp at nicira.com
Thu Dec 9 00:27:06 UTC 2010


Requested-by: Natasha Gude <natasha at nicira.com>
---
 lib/ofp-print.c |   50 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index aebd381..fc18390 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -1005,31 +1005,41 @@ ofp_print_error(struct ds *string, int error)
 }
 
 static void
-ofp_print_error_msg(struct ds *string, const struct ofp_error_msg *oem)
+ofp_print_error_msg(struct ds *string, const struct ofp_header *oh)
 {
-    size_t len = ntohs(oem->header.length);
-    int type = ntohs(oem->type);
-    int code = ntohs(oem->code);
-    char *s;
+    struct ofp_error_msg *oem;
+    struct ofpbuf b;
 
-    ds_put_format(string, " type:%d(%s) code:%d(%s) payload:\n",
-                  type, lookup_error_type(type),
-                  code, lookup_error_code(type, code));
+    ofpbuf_use_const(&b, oh, ntohs(oh->length));
 
-    switch (type) {
-    case OFPET_HELLO_FAILED:
-        ds_put_printable(string, (char *) oem->data, len - sizeof *oem);
-        break;
+    oem = ofpbuf_pull(&b, sizeof *oem);
+    if (oem->type == htons(NXET_VENDOR)
+        && oem->code == htons(NXVC_VENDOR_ERROR)) {
+        struct nx_vendor_error *nve = ofpbuf_try_pull(&b, sizeof *nve);
+        if (!nve) {
+            ds_put_format(string, " truncated vendor error");
+            return;
+        }
 
-    case OFPET_BAD_REQUEST:
-        s = ofp_to_string(oem->data, len - sizeof *oem, 1);
-        ds_put_cstr(string, s);
-        free(s);
-        break;
+        ds_put_format(string, " vendor:%08"PRIx32" type:%"PRIu16" "
+                      "code:%"PRIu16" payload:\n",
+                      ntohl(nve->vendor), ntohs(nve->type),
+                      ntohs(nve->code));
 
-    default:
-        ds_put_hex_dump(string, oem->data, len - sizeof *oem, 0, true);
-        break;
+        ds_put_hex_dump(string, b.data, b.size, 0, true);
+    } else {
+        int type = ntohs(oem->type);
+        int code = ntohs(oem->code);
+
+        ds_put_format(string, " type:%d(%s) code:%d(%s) payload:\n",
+                      type, lookup_error_type(type),
+                      code, lookup_error_code(type, code));
+
+        if (type == OFPET_HELLO_FAILED) {
+            ds_put_printable(string, b.data, b.size);
+        } else {
+            ds_put_hex_dump(string, b.data, b.size, 0, true);
+        }
     }
 }
 
-- 
1.7.1





More information about the dev mailing list