got_type_name, want_type_name);
free(want_type_name);
free(got_type_name);
- return false;
+ return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_TYPE);
}
- return true;
+ return 0;
}
/* Checks that 'msg' has type 'type' and that it is exactly 'size' bytes long.
- * Returns 0 if the checks pass, otherwise EINVAL. */
+ * Returns 0 if the checks pass, otherwise an OpenFlow error code (produced
+ * with ofp_mkerr()). */
int
check_ofp_message(const struct ofp_header *msg, uint8_t type, size_t size)
{
size_t got_size;
+ int error;
- if (!check_message_type(msg->type, type)) {
- return EINVAL;
+ error = check_message_type(msg->type, type);
+ if (error) {
+ return error;
}
got_size = ntohs(msg->length);
"received %s message of length %"PRIu16" (expected %zu)",
type_name, got_size, size);
free(type_name);
- return EINVAL;
+ return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LENGTH);
}
return 0;
/* Checks that 'msg' has type 'type' and that 'msg' is 'size' plus a
* nonnegative integer multiple of 'array_elt_size' bytes long. Returns 0 if
- * the checks pass, otherwise EINVAL.
+ * the checks pass, otherwise an OpenFlow error code (produced with
+ * ofp_mkerr()).
*
* If 'n_array_elts' is nonnull, then '*n_array_elts' is set to the number of
* 'array_elt_size' blocks in 'msg' past the first 'min_size' bytes, when
size_t *n_array_elts)
{
size_t got_size;
+ int error;
assert(array_elt_size);
- if (!check_message_type(msg->type, type)) {
- return EINVAL;
+ error = check_message_type(msg->type, type);
+ if (error) {
+ return error;
}
got_size = ntohs(msg->length);
"(expected at least %zu)",
type_name, got_size, min_size);
free(type_name);
- return EINVAL;
+ return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LENGTH);
}
if ((got_size - min_size) % array_elt_size) {
char *type_name = ofp_message_type_to_string(type);
type_name, got_size, min_size, got_size - min_size,
array_elt_size, (got_size - min_size) % array_elt_size);
free(type_name);
- return EINVAL;
+ return ofp_mkerr(OFPET_BAD_REQUEST, OFPBRC_BAD_LENGTH);
}
if (n_array_elts) {
*n_array_elts = (got_size - min_size) / array_elt_size;