git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Don't use error categories as if they were actually errors.
[sliver-openvswitch.git]
/
lib
/
ofp-errors.c
diff --git
a/lib/ofp-errors.c
b/lib/ofp-errors.c
index
e1349b0
..
f2df8ae
100644
(file)
--- a/
lib/ofp-errors.c
+++ b/
lib/ofp-errors.c
@@
-3,6
+3,7
@@
#include <errno.h>
#include "byte-order.h"
#include "dynamic-string.h"
#include <errno.h>
#include "byte-order.h"
#include "dynamic-string.h"
+#include "ofp-msgs.h"
#include "ofp-util.h"
#include "ofpbuf.h"
#include "openflow/openflow.h"
#include "ofp-util.h"
#include "ofpbuf.h"
#include "openflow/openflow.h"
@@
-20,20
+21,29
@@
struct pair {
* 'version' (one of the possible values of struct ofp_header's 'version'
* member). Returns NULL if the version isn't defined or isn't understood by
* OVS. */
* 'version' (one of the possible values of struct ofp_header's 'version'
* member). Returns NULL if the version isn't defined or isn't understood by
* OVS. */
-const struct ofperr_domain *
-ofperr_domain_from_version(
uint8_t
version)
+
static
const struct ofperr_domain *
+ofperr_domain_from_version(
enum ofp_version
version)
{
{
- return (version == ofperr_of10.version ? &ofperr_of10
- : version == ofperr_of11.version ? &ofperr_of11
- : version == ofperr_of12.version ? &ofperr_of12
- : NULL);
+ switch (version) {
+ case OFP10_VERSION:
+ return &ofperr_of10;
+ case OFP11_VERSION:
+ return &ofperr_of11;
+ case OFP12_VERSION:
+ return &ofperr_of12;
+ case OFP13_VERSION:
+ return &ofperr_of13;
+ default:
+ return NULL;
+ }
}
}
-/* Returns the name (e.g. "OpenFlow 1.0") of OpenFlow
error domain 'domai
n'. */
+/* Returns the name (e.g. "OpenFlow 1.0") of OpenFlow
version 'versio
n'. */
const char *
const char *
-ofperr_domain_get_name(
const struct ofperr_domain *domai
n)
+ofperr_domain_get_name(
enum ofp_version versio
n)
{
{
- return domain->name;
+ const struct ofperr_domain *domain = ofperr_domain_from_version(version);
+ return domain ? domain->name : NULL;
}
/* Returns true if 'error' is a valid OFPERR_* value, false otherwise. */
}
/* Returns true if 'error' is a valid OFPERR_* value, false otherwise. */
@@
-70,26
+80,31
@@
ofperr_is_nx_extension(enum ofperr error)
* A given error may not be encodable in some domains because each OpenFlow
* version tends to introduce new errors and retire some old ones. */
bool
* A given error may not be encodable in some domains because each OpenFlow
* version tends to introduce new errors and retire some old ones. */
bool
-ofperr_is_encodable(enum ofperr error,
const struct ofperr_domain *domai
n)
+ofperr_is_encodable(enum ofperr error,
enum ofp_version versio
n)
{
{
+ const struct ofperr_domain *domain = ofperr_domain_from_version(version);
return (ofperr_is_valid(error)
return (ofperr_is_valid(error)
- && domain->errors[error - OFPERR_OFS].code >= 0);
+ && domain
&& domain
->errors[error - OFPERR_OFS].code >= 0);
}
/* Returns the OFPERR_* value that corresponds to 'type' and 'code' within
}
/* Returns the OFPERR_* value that corresponds to 'type' and 'code' within
- * 'domain', or 0 if no such OFPERR_* value exists. */
+ * 'version', or 0 if either no such OFPERR_* value exists or 'version' is
+ * unknown. */
enum ofperr
enum ofperr
-ofperr_decode(
const struct ofperr_domain *domai
n, uint16_t type, uint16_t code)
+ofperr_decode(
enum ofp_version versio
n, uint16_t type, uint16_t code)
{
{
- return domain->decode(type, code);
+ const struct ofperr_domain *domain = ofperr_domain_from_version(version);
+ return domain ? domain->decode(type, code) : 0;
}
/* Returns the OFPERR_* value that corresponds to the category 'type' within
}
/* Returns the OFPERR_* value that corresponds to the category 'type' within
- * 'domain', or 0 if no such OFPERR_* value exists. */
+ * 'version', or 0 if either no such OFPERR_* value exists or 'version' is
+ * unknown. */
enum ofperr
enum ofperr
-ofperr_decode_type(
const struct ofperr_domain *domai
n, uint16_t type)
+ofperr_decode_type(
enum ofp_version versio
n, uint16_t type)
{
{
- return domain->decode_type(type);
+ const struct ofperr_domain *domain = ofperr_domain_from_version(version);
+ return domain ? domain->decode_type(type) : 0;
}
/* Returns the name of 'error', e.g. "OFPBRC_BAD_TYPE" if 'error' is
}
/* Returns the name of 'error', e.g. "OFPBRC_BAD_TYPE" if 'error' is
@@
-144,18
+159,20
@@
ofperr_get_pair__(enum ofperr error, const struct ofperr_domain *domain)
}
static struct ofpbuf *
}
static struct ofpbuf *
-ofperr_encode_msg__(enum ofperr error,
const struct ofperr_domain *domai
n,
+ofperr_encode_msg__(enum ofperr error,
enum ofp_version ofp_versio
n,
ovs_be32 xid, const void *data, size_t data_len)
{
struct ofp_error_msg *oem;
const struct pair *pair;
struct ofpbuf *buf;
ovs_be32 xid, const void *data, size_t data_len)
{
struct ofp_error_msg *oem;
const struct pair *pair;
struct ofpbuf *buf;
+ const struct ofperr_domain *domain;
+ domain = ofperr_domain_from_version(ofp_version);
if (!domain) {
return NULL;
}
if (!domain) {
return NULL;
}
- if (!ofperr_is_encodable(error,
domai
n)) {
+ if (!ofperr_is_encodable(error,
ofp_versio
n)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
if (!ofperr_is_valid(error)) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
if (!ofperr_is_valid(error)) {
@@
-176,25
+193,28
@@
ofperr_encode_msg__(enum ofperr error, const struct ofperr_domain *domain,
pair = ofperr_get_pair__(error, domain);
if (!ofperr_is_nx_extension(error)) {
pair = ofperr_get_pair__(error, domain);
if (!ofperr_is_nx_extension(error)) {
- oem = make_openflow_xid(data_len + sizeof *oem, OFPT_ERROR, xid, &buf);
+ buf = ofpraw_alloc_xid(OFPRAW_OFPT_ERROR, domain->version, xid,
+ sizeof *oem + data_len);
+
+ oem = ofpbuf_put_uninit(buf, sizeof *oem);
oem->type = htons(pair->type);
oem->code = htons(pair->code);
} else {
struct nx_vendor_error *nve;
oem->type = htons(pair->type);
oem->code = htons(pair->code);
} else {
struct nx_vendor_error *nve;
- oem = make_openflow_xid(data_len + sizeof *oem + sizeof *nve,
- OFPT_ERROR, xid, &buf);
+ buf = ofpraw_alloc_xid(OFPRAW_OFPT_ERROR, domain->version, xid,
+ sizeof *oem + sizeof *nve + data_len);
+
+ oem = ofpbuf_put_uninit(buf, sizeof *oem);
oem->type = htons(NXET_VENDOR);
oem->code = htons(NXVC_VENDOR_ERROR);
oem->type = htons(NXET_VENDOR);
oem->code = htons(NXVC_VENDOR_ERROR);
- nve =
(struct nx_vendor_error *) oem->data
;
+ nve =
ofpbuf_put_uninit(buf, sizeof *nve)
;
nve->vendor = htonl(NX_VENDOR_ID);
nve->type = htons(pair->type);
nve->code = htons(pair->code);
}
nve->vendor = htonl(NX_VENDOR_ID);
nve->type = htons(pair->type);
nve->code = htons(pair->code);
}
- oem->header.version = domain->version;
- buf->size -= data_len;
ofpbuf_put(buf, data, data_len);
return buf;
ofpbuf_put(buf, data, data_len);
return buf;
@@
-216,90
+236,92
@@
ofperr_encode_msg__(enum ofperr error, const struct ofperr_domain *domain,
struct ofpbuf *
ofperr_encode_reply(enum ofperr error, const struct ofp_header *oh)
{
struct ofpbuf *
ofperr_encode_reply(enum ofperr error, const struct ofp_header *oh)
{
- const struct ofperr_domain *domain;
uint16_t len = ntohs(oh->length);
uint16_t len = ntohs(oh->length);
- domain = ofperr_domain_from_version(oh->version);
- return ofperr_encode_msg__(error, domain, oh->xid, oh, MIN(len, 64));
+ return ofperr_encode_msg__(error, oh->version, oh->xid, oh, MIN(len, 64));
}
/* Creates and returns an OpenFlow message of type OFPT_ERROR that conveys the
* given 'error', in the error domain 'domain'. The error message will include
* the additional null-terminated text string 's'.
*
}
/* Creates and returns an OpenFlow message of type OFPT_ERROR that conveys the
* given 'error', in the error domain 'domain'. The error message will include
* the additional null-terminated text string 's'.
*
- * If '
domain' is NULL, uses the OpenFlow 1.0 error domain. OFPET_HELLO_FAILED
- *
error messages are supposed to be backward-compatible, so in theory this
- * should work.
+ * If '
version' is an unknown version then OFP10_VERSION is used.
+ *
OFPET_HELLO_FAILED error messages are supposed to be backward-compatible,
+ * s
o in theory this s
hould work.
*
* Returns NULL if 'error' is not an OpenFlow error code or if 'error' cannot
* be encoded in 'domain'. */
struct ofpbuf *
*
* Returns NULL if 'error' is not an OpenFlow error code or if 'error' cannot
* be encoded in 'domain'. */
struct ofpbuf *
-ofperr_encode_hello(enum ofperr error,
const struct ofperr_domain *domai
n,
+ofperr_encode_hello(enum ofperr error,
enum ofp_version ofp_versio
n,
const char *s)
{
const char *s)
{
- if (!domain) {
- domain = &ofperr_of10;
+ switch (ofp_version) {
+ case OFP10_VERSION:
+ case OFP11_VERSION:
+ case OFP12_VERSION:
+ case OFP13_VERSION:
+ break;
+
+ default:
+ ofp_version = OFP10_VERSION;
}
}
- return ofperr_encode_msg__(error, domain, htonl(0), s, strlen(s));
+
+ return ofperr_encode_msg__(error, ofp_version, htonl(0), s, strlen(s));
}
/* Returns the value that would go into an OFPT_ERROR message's 'type' for
* encoding 'error' in 'domain'. Returns -1 if 'error' is not encodable in
}
/* Returns the value that would go into an OFPT_ERROR message's 'type' for
* encoding 'error' in 'domain'. Returns -1 if 'error' is not encodable in
- * '
domain'
.
+ * '
version' or 'version' is unknown
.
*
* 'error' must be a valid OFPERR_* code, as checked by ofperr_is_valid(). */
int
*
* 'error' must be a valid OFPERR_* code, as checked by ofperr_is_valid(). */
int
-ofperr_get_type(enum ofperr error,
const struct ofperr_domain *domai
n)
+ofperr_get_type(enum ofperr error,
enum ofp_version versio
n)
{
{
- return ofperr_get_pair__(error, domain)->type;
+ const struct ofperr_domain *domain = ofperr_domain_from_version(version);
+ return domain ? ofperr_get_pair__(error, domain)->type : -1;
}
/* Returns the value that would go into an OFPT_ERROR message's 'code' for
* encoding 'error' in 'domain'. Returns -1 if 'error' is not encodable in
}
/* Returns the value that would go into an OFPT_ERROR message's 'code' for
* encoding 'error' in 'domain'. Returns -1 if 'error' is not encodable in
- * 'domain' or if 'error' represents a category rather than a specific error.
+ * 'version', 'version' is unknown or if 'error' represents a category
+ * rather than a specific error.
+ *
*
* 'error' must be a valid OFPERR_* code, as checked by ofperr_is_valid(). */
int
*
* 'error' must be a valid OFPERR_* code, as checked by ofperr_is_valid(). */
int
-ofperr_get_code(enum ofperr error,
const struct ofperr_domain *domai
n)
+ofperr_get_code(enum ofperr error,
enum ofp_version versio
n)
{
{
- return ofperr_get_pair__(error, domain)->code;
+ const struct ofperr_domain *domain = ofperr_domain_from_version(version);
+ return domain ? ofperr_get_pair__(error, domain)->code : -1;
}
}
-/* Tries to decode
s
'oh', which should be an OpenFlow OFPT_ERROR message.
+/* Tries to decode 'oh', which should be an OpenFlow OFPT_ERROR message.
* Returns an OFPERR_* constant on success, 0 on failure.
*
* Returns an OFPERR_* constant on success, 0 on failure.
*
- * If 'payload
_ofs' is nonnull, on success '*payload_ofs' is set to the offset
- *
to the payload starting from 'oh' and on failure it is set to 0
. */
+ * If 'payload
' is nonnull, on success '*payload' is initialized to the
+ *
error's payload, and on failure it is cleared
. */
enum ofperr
enum ofperr
-ofperr_decode_msg(const struct ofp_header *oh, s
ize_t *payload_ofs
)
+ofperr_decode_msg(const struct ofp_header *oh, s
truct ofpbuf *payload
)
{
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
{
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
- const struct ofperr_domain *domain;
const struct ofp_error_msg *oem;
const struct ofp_error_msg *oem;
+ enum ofpraw raw;
uint16_t type, code;
enum ofperr error;
struct ofpbuf b;
uint16_t type, code;
enum ofperr error;
struct ofpbuf b;
- if (payload
_ofs
) {
-
*payload_ofs = 0
;
+ if (payload) {
+
memset(payload, 0, sizeof *payload)
;
}
/* Pull off the error message. */
ofpbuf_use_const(&b, oh, ntohs(oh->length));
}
/* Pull off the error message. */
ofpbuf_use_const(&b, oh, ntohs(oh->length));
- oem = ofpbuf_try_pull(&b, sizeof *oem);
- if (!oem) {
- return 0;
- }
-
- /* Check message type and version. */
- if (oh->type != OFPT_ERROR) {
- return 0;
- }
- domain = ofperr_domain_from_version(oh->version);
- if (!domain) {
+ error = ofpraw_pull(&raw, &b);
+ if (error) {
return 0;
}
return 0;
}
+ oem = ofpbuf_pull(&b, sizeof *oem);
/* Get the error type and code. */
type = ntohs(oem->type);
/* Get the error type and code. */
type = ntohs(oem->type);
@@
-321,12
+343,12
@@
ofperr_decode_msg(const struct ofp_header *oh, size_t *payload_ofs)
/* Translate the error type and code into an ofperr.
* If we don't know the error type and code, at least try for the type. */
/* Translate the error type and code into an ofperr.
* If we don't know the error type and code, at least try for the type. */
- error = ofperr_decode(
domai
n, type, code);
+ error = ofperr_decode(
oh->versio
n, type, code);
if (!error) {
if (!error) {
- error = ofperr_decode_type(
domai
n, type);
+ error = ofperr_decode_type(
oh->versio
n, type);
}
}
- if (error && payload
_ofs
) {
-
*payload_ofs = (uint8_t *) b.data - (uint8_t *) oh
;
+ if (error && payload) {
+
ofpbuf_use_const(payload, b.data, b.size)
;
}
return error;
}
}
return error;
}