From: Ben Pfaff Date: Mon, 18 Jan 2016 22:55:30 +0000 (-0800) Subject: nx-match: Add functions for raw decoding and encoding of OXM. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=9f6e20b70e1117037dda056bda39b02c769aa8cd nx-match: Add functions for raw decoding and encoding of OXM. The existing functions either assumed that we were working with NXM (instead of OXM), or they added or parsed a header before OXM headers. These aren't needed when OXM is encapsulated inside a property, as will be the case in an upcoming commit. Signed-off-by: Ben Pfaff Acked-by: Jarno Rajahalme --- diff --git a/lib/nx-match.c b/lib/nx-match.c index 11bcd950d..0f695f042 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc. + * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015, 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. @@ -630,6 +630,18 @@ oxm_pull_match_loose(struct ofpbuf *b, struct match *match) return oxm_pull_match__(b, false, match); } +/* Parses the OXM match description in the 'oxm_len' bytes in 'oxm'. Stores + * the result in 'match'. + * + * Fails with an error when encountering unknown OXM headers. + * + * Returns 0 if successful, otherwise an OpenFlow error code. */ +enum ofperr +oxm_decode_match(const void *oxm, size_t oxm_len, struct match *match) +{ + return nx_pull_raw(oxm, oxm_len, true, match, NULL, NULL); +} + /* Verify an array of OXM TLVs treating value of each TLV as a mask, * disallowing masks in each TLV and ignoring pre-requisites. */ enum ofperr @@ -1099,7 +1111,7 @@ nx_put_match(struct ofpbuf *b, const struct match *match, } /* Appends to 'b' an struct ofp11_match_header followed by the OXM format that - * expresses 'cr', plus enough zero bytes to pad the data appended out to a + * expresses 'match', plus enough zero bytes to pad the data appended out to a * multiple of 8. * * OXM differs slightly among versions of OpenFlow. Specify the OpenFlow @@ -1130,6 +1142,20 @@ oxm_put_match(struct ofpbuf *b, const struct match *match, return match_len; } +/* Appends to 'b' the OXM formats that expresses 'match', without header or + * padding. + * + * OXM differs slightly among versions of OpenFlow. Specify the OpenFlow + * version in use as 'version'. + * + * This function can cause 'b''s data to be reallocated. */ +void +oxm_put_raw(struct ofpbuf *b, const struct match *match, + enum ofp_version version) +{ + nx_put_raw(b, version, match, 0, 0); +} + /* Appends to 'b' the nx_match format that expresses the tlv corresponding * to 'id'. If mask is not all-ones then it is also formated as the value * of the tlv. */ diff --git a/lib/nx-match.h b/lib/nx-match.h index 2625c63c2..c663e54ce 100644 --- a/lib/nx-match.h +++ b/lib/nx-match.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, 2012, 2013, 2014 Nicira, Inc. + * Copyright (c) 2010, 2011, 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. @@ -47,6 +47,7 @@ char *mf_parse_subfield__(struct mf_subfield *sf, const char **s) char *mf_parse_subfield(struct mf_subfield *, const char *s) OVS_WARN_UNUSED_RESULT; +/* Decoding matches. */ enum ofperr nx_pull_match(struct ofpbuf *, unsigned int match_len, struct match *, ovs_be64 *cookie, ovs_be64 *cookie_mask); @@ -55,11 +56,15 @@ enum ofperr nx_pull_match_loose(struct ofpbuf *, unsigned int match_len, ovs_be64 *cookie_mask); enum ofperr oxm_pull_match(struct ofpbuf *, struct match *); enum ofperr oxm_pull_match_loose(struct ofpbuf *, struct match *); +enum ofperr oxm_decode_match(const void *, size_t, struct match *); enum ofperr oxm_pull_field_array(const void *, size_t fields_len, struct field_array *); + +/* Encoding matches. */ int nx_put_match(struct ofpbuf *, const struct match *, ovs_be64 cookie, ovs_be64 cookie_mask); int oxm_put_match(struct ofpbuf *, const struct match *, enum ofp_version); +void oxm_put_raw(struct ofpbuf *, const struct match *, enum ofp_version); void oxm_format_field_array(struct ds *, const struct field_array *); int oxm_put_field_array(struct ofpbuf *, const struct field_array *, enum ofp_version version);