From: Isaku Yamahata <yamah...@valinux.co.jp> Signed-off-by: Isaku Yamahata <yamah...@valinux.co.jp> Signed-off-by: Simon Horman <ho...@verge.net.au>
--- v5 [Simon Horman] * Do not add mf_check_dst_oxm(), just use mf_check_dst(). v4 [Simon Horman] * Remove utilities/ovs-ofctl.c hunk, introduced in v3, which belongs in a different patch * Make use of new oxm_writable field in struct mf_subfield to implement mf_check_dst_oxm(). This provides more strict checking than the previous implementation. * Do not call pre-requisites explicitly in mf_are_prereqs_ok() - It will segfault as flow is NULL - It would be called by mf_is_value_valid() if flow was not NULL * Correct byte-order issues in nxm_reg_load_from_openflow12_set_field() * Add set_field_format() and use it in nxm_format_reg_load() * Update to use mf_subfield v3 [Simon Horman] * Add (now) missing cases to nxm_reg_load_check() v2 [Isaku Yamahata] * First post --- lib/nx-match.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- lib/nx-match.h | 2 ++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/lib/nx-match.c b/lib/nx-match.c index 1ff58bb..b1eb9e2 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -1022,8 +1022,23 @@ nxm_format_reg_move(const struct ofpact_reg_move *move, struct ds *s) mf_format_subfield(&move->dst, s); } -void -nxm_format_reg_load(const struct ofpact_reg_load *load, struct ds *s) +static void +set_field_format(const struct ofpact_reg_load *load, struct ds *s) +{ + const struct mf_field *mf = load->dst.field; + union mf_value value; + + assert(load->ofpact.compat == OFPUTIL_OFPAT12_SET_FIELD); + ds_put_format(s, "set_field:"); + memset(&value, 0, sizeof value); + bitwise_copy(&load->subvalue, sizeof load->subvalue, load->dst.ofs, + &value, mf->n_bytes, 0, load->dst.n_bits); + mf_format(mf, &value, NULL, s); + ds_put_format(s, "->%s", mf->name); +} + +static void +load_format(const struct ofpact_reg_load *load, struct ds *s) { union mf_subvalue right_justified; @@ -1037,6 +1052,16 @@ nxm_format_reg_load(const struct ofpact_reg_load *load, struct ds *s) ds_put_cstr(s, "->"); mf_format_subfield(&load->dst, s); } + +void +nxm_format_reg_load(const struct ofpact_reg_load *load, struct ds *s) +{ + if (load->ofpact.compat == OFPUTIL_OFPAT12_SET_FIELD) { + set_field_format(load, s); + } else { + load_format(load, s); + } +} enum ofperr nxm_reg_move_from_openflow(const struct nx_action_reg_move *narm, @@ -1079,6 +1104,47 @@ nxm_reg_load_from_openflow(const struct nx_action_reg_load *narl, return nxm_reg_load_check(load, NULL); } + +enum ofperr +nxm_reg_load_from_openflow12_set_field( + const struct ofp12_action_set_field * oasf, struct ofpbuf *ofpacts) +{ + uint16_t oasf_len = ntohs(oasf->len); + ovs_be32 *p = (ovs_be32*)oasf->field; + uint32_t oxm_header = ntohl(*p); + uint8_t oxm_length = NXM_LENGTH(oxm_header); + struct ofpact_reg_load *load; + const struct mf_field *mf; + int i; + + /* ofp12_action_set_field is padded to 64 bits by zero */ + if (oasf_len != ROUND_UP(sizeof(*oasf) + oxm_length, 8)) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } + for (i = sizeof(*oasf) + oxm_length; i < oasf_len; i++) { + if (((const char*)oasf)[i]) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } + } + + if (NXM_HASMASK(oxm_header)) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } + mf = mf_from_nxm_header(oxm_header); + if (!mf || mf->oxm_header == 0) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } + load = ofpact_put_REG_LOAD(ofpacts); + load->ofpact.compat = OFPUTIL_OFPAT12_SET_FIELD; + load->dst.field = mf; + load->dst.ofs = 0; + load->dst.n_bits = mf->n_bits; + bitwise_copy(oasf + 1, mf->n_bytes, load->dst.ofs, + &load->subvalue, sizeof load->subvalue, load->dst.ofs, + mf->n_bits); + + return nxm_reg_load_check(load, NULL); +} enum ofperr nxm_reg_move_check(const struct ofpact_reg_move *move, const struct flow *flow) @@ -1096,6 +1162,22 @@ nxm_reg_move_check(const struct ofpact_reg_move *move, const struct flow *flow) enum ofperr nxm_reg_load_check(const struct ofpact_reg_load *load, const struct flow *flow) { + const struct mf_field *mf; + union mf_value value; + + if (load->ofpact.compat != OFPUTIL_OFPAT12_SET_FIELD) { + return mf_check_dst(&load->dst, flow); + } + + mf = load->dst.field; + + memset(&value, 0, sizeof value); + bitwise_copy(&load->subvalue, sizeof load->subvalue, load->dst.ofs, + &value, load->dst.field->n_bytes, load->dst.ofs, + load->dst.n_bits); + if (!mf_is_value_valid(mf, &value)) { + return OFPERR_OFPBAC_BAD_ARGUMENT; + } return mf_check_dst(&load->dst, flow); } @@ -1119,6 +1201,18 @@ nxm_reg_load_to_nxast(const struct ofpact_reg_load *load, { struct nx_action_reg_load *narl; + if (load->ofpact.compat == OFPUTIL_OFPAT12_SET_FIELD) { + const struct mf_field *mf = load->dst.field; + struct ofp12_action_set_field *oasf; + + oasf = ofputil_put_OFPAT12_SET_FIELD(openflow); + *(uint32_t *)oasf->field = mf->oxm_header; + memset(oasf + 1, 0, mf->n_bytes); + bitwise_copy(&load->subvalue, sizeof load->subvalue, load->dst.ofs, + oasf + 1, mf->n_bytes, load->dst.ofs, load->dst.n_bits); + return; + } + narl = ofputil_put_NXAST_REG_LOAD(openflow); narl->ofs_nbits = nxm_encode_ofs_nbits(load->dst.ofs, load->dst.n_bits); narl->dst = htonl(load->dst.field->nxm_header); diff --git a/lib/nx-match.h b/lib/nx-match.h index f504ad0..6a57297 100644 --- a/lib/nx-match.h +++ b/lib/nx-match.h @@ -65,6 +65,8 @@ enum ofperr nxm_reg_move_from_openflow(const struct nx_action_reg_move *, struct ofpbuf *ofpacts); enum ofperr nxm_reg_load_from_openflow(const struct nx_action_reg_load *, struct ofpbuf *ofpacts); +enum ofperr nxm_reg_load_from_openflow12_set_field( + const struct ofp12_action_set_field * oasf, struct ofpbuf *ofpacts); enum ofperr nxm_reg_move_check(const struct ofpact_reg_move *, const struct flow *); -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev