odp-util: Format and scan multiple MPLS labels.
[cascardo/ovs.git] / lib / ofp-errors.c
index 5285645..f9e1fa9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2012, 2013, 2014, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
 #include "ofp-util.h"
 #include "ofpbuf.h"
 #include "openflow/openflow.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(ofp_errors);
 
@@ -50,6 +50,10 @@ ofperr_domain_from_version(enum ofp_version version)
         return &ofperr_of12;
     case OFP13_VERSION:
         return &ofperr_of13;
+    case OFP14_VERSION:
+        return &ofperr_of14;
+    case OFP15_VERSION:
+        return &ofperr_of15;
     default:
         return NULL;
     }
@@ -154,7 +158,7 @@ ofperr_encode_msg__(enum ofperr error, enum ofp_version ofp_version,
     if (!ofperr_is_valid(error)) {
         /* 'error' seems likely to be a system errno value. */
         VLOG_ERR_RL(&rl, "invalid OpenFlow error code %d (%s)",
-                    error, strerror(error));
+                    error, ovs_strerror(error));
         error = OFPERR_NXBRC_UNENCODABLE_ERROR;
     } else if (domain->errors[error - OFPERR_OFS].code < 0) {
         VLOG_ERR_RL(&rl, "cannot encode %s for %s",
@@ -270,25 +274,25 @@ ofperr_get_code(enum ofperr error, enum ofp_version version)
 /* Tries to decode 'oh', which should be an OpenFlow OFPT_ERROR message.
  * Returns an OFPERR_* constant on success, 0 on failure.
  *
- * If 'payload' is nonnull, on success '*payload' is initialized to the
- * error's payload, and on failure it is cleared. */
+ * If 'payload' is nonnull, on success '*payload' is initialized with a copy of
+ * the error's payload (copying is required because the payload is not properly
+ * aligned).  The caller must free the payload (with ofpbuf_uninit()) when it
+ * is no longer needed.  On failure, '*payload' is cleared. */
 enum ofperr
 ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload)
 {
     const struct ofp_error_msg *oem;
     enum ofpraw raw;
     uint16_t type, code;
-    enum ofperr error;
     uint32_t vendor;
-    struct ofpbuf b;
 
     if (payload) {
         memset(payload, 0, sizeof *payload);
     }
 
     /* Pull off the error message. */
-    ofpbuf_use_const(&b, oh, ntohs(oh->length));
-    error = ofpraw_pull(&raw, &b);
+    struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));
+    enum ofperr error = ofpraw_pull(&raw, &b);
     if (error) {
         return 0;
     }
@@ -321,17 +325,20 @@ ofperr_decode_msg(const struct ofp_header *oh, struct ofpbuf *payload)
     /* Translate the error type and code into an ofperr. */
     error = ofperr_decode(oh->version, vendor, type, code);
     if (error && payload) {
-        ofpbuf_use_const(payload, b.data, b.size);
+        ofpbuf_init(payload, b.size);
+        ofpbuf_push(payload, b.data, b.size);
     }
     return error;
 }
 
 /* If 'error' is a valid OFPERR_* value, returns its name
  * (e.g. "OFPBRC_BAD_TYPE" for OFPBRC_BAD_TYPE).  Otherwise, assumes that
- * 'error' is a positive errno value and returns what strerror() produces for
- * 'error'.  */
+ * 'error' is a positive errno value and returns what ovs_strerror() produces
+ * for 'error'.  */
 const char *
 ofperr_to_string(enum ofperr error)
 {
-    return ofperr_is_valid(error) ? ofperr_get_name(error) : strerror(error);
+    return (ofperr_is_valid(error)
+            ? ofperr_get_name(error)
+            : ovs_strerror(error));
 }