From: Ben Pfaff Date: Mon, 2 Mar 2009 19:13:14 +0000 (-0800) Subject: vconn: Make check_ofp_message() return value more useful. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36adf7631ee8dff82b2e0f55af131f141e1611fe;p=openvswitch vconn: Make check_ofp_message() return value more useful. --- diff --git a/lib/vconn.c b/lib/vconn.c index f43b35f1..f44fdbc2 100644 --- a/lib/vconn.c +++ b/lib/vconn.c @@ -1015,20 +1015,23 @@ check_message_type(uint8_t got_type, uint8_t want_type) 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); @@ -1038,7 +1041,7 @@ check_ofp_message(const struct ofp_header *msg, uint8_t type, size_t size) "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; @@ -1046,7 +1049,8 @@ check_ofp_message(const struct ofp_header *msg, uint8_t type, size_t size) /* 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 @@ -1057,11 +1061,13 @@ check_ofp_message_array(const struct ofp_header *msg, uint8_t type, 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); @@ -1071,7 +1077,7 @@ check_ofp_message_array(const struct ofp_header *msg, uint8_t type, "(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); @@ -1082,7 +1088,7 @@ check_ofp_message_array(const struct ofp_header *msg, uint8_t 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;