From: Isaku Yamahata <yamah...@valinux.co.jp> Use a uninion mf_subvalue instead of a uint64_t for the value member of struct ofpact_reg_load.
set_field action needs to hold values wider than 64 bits. This is preparation for set_field action. Signed-off-by: Isaku Yamahata <yamah...@valinux.co.jp> Signed-off-by: Simon Horman <ho...@verge.net.au> --- v4 [Simon Horman] * Use union mf_subfield instead of union mf_value as suggested by Ben Pfaff v3 * No change v2 [Isaku Yamahata] * First post --- lib/learn.c | 8 +------- lib/meta-flow.c | 16 ++++++++++++++++ lib/meta-flow.h | 2 ++ lib/nx-match.c | 45 +++++++++++++++++++++++++++++---------------- lib/ofp-actions.h | 4 ++-- 5 files changed, 50 insertions(+), 25 deletions(-) diff --git a/lib/learn.c b/lib/learn.c index cd75321..1b65be1 100644 --- a/lib/learn.c +++ b/lib/learn.c @@ -339,7 +339,6 @@ learn_execute(const struct ofpact_learn *learn, const struct flow *flow, case NX_LEARN_DST_LOAD: for (ofs = 0; ofs < spec->n_bits; ofs += chunk) { struct ofpact_reg_load *load; - ovs_be64 value_be; chunk = MIN(spec->n_bits - ofs, 64); @@ -347,12 +346,7 @@ learn_execute(const struct ofpact_learn *learn, const struct flow *flow, load->dst.field = spec->dst.field; load->dst.ofs = spec->dst.ofs + ofs; load->dst.n_bits = chunk; - - memset(&value_be, 0, sizeof value_be); - bitwise_copy(&value, sizeof value, ofs, - &value_be, sizeof value_be, 0, - chunk); - load->value = ntohll(value_be); + load->subvalue = value; } break; diff --git a/lib/meta-flow.c b/lib/meta-flow.c index 0de9b45..e4b51c0 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -2153,6 +2153,22 @@ mf_format(const struct mf_field *mf, } } +/* Makes subfield 'sf' within 'flow' exactly match the 'sf->n_bits' + * least-significant bits in 'x'. + */ +void +mf_write_subfield_flow(const struct mf_subfield *sf, + const union mf_subvalue *x, struct flow *flow) +{ + const struct mf_field *field = sf->field; + union mf_value value; + + mf_get_value(field, flow, &value); + bitwise_copy(x, sizeof *x, sf->ofs, &value, field->n_bytes, + sf->ofs, sf->n_bits); + mf_set_flow_value(field, &value, flow); +} + /* Makes subfield 'sf' within 'match' exactly match the 'sf->n_bits' * least-significant bits in 'x'. */ diff --git a/lib/meta-flow.h b/lib/meta-flow.h index 8c8b7be..11a9db9 100644 --- a/lib/meta-flow.h +++ b/lib/meta-flow.h @@ -318,6 +318,8 @@ void mf_set_wild(const struct mf_field *, struct match *); void mf_random_value(const struct mf_field *, union mf_value *value); /* Subfields. */ +void mf_write_subfield_flow(const struct mf_subfield *, + const union mf_subvalue *, struct flow *); void mf_write_subfield(const struct mf_subfield *, const union mf_subvalue *, struct match *); diff --git a/lib/nx-match.c b/lib/nx-match.c index 9f9184a..6fa583e 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -988,8 +988,9 @@ void nxm_parse_reg_load(struct ofpact_reg_load *load, const char *s) { const char *full_s = s; + uint64_t value = strtoull(s, (char **) &s, 0); + ovs_be64 value_be = htonll(value); - load->value = strtoull(s, (char **) &s, 0); if (strncmp(s, "->", 2)) { ovs_fatal(0, "%s: missing `->' following value", full_s); } @@ -999,10 +1000,15 @@ nxm_parse_reg_load(struct ofpact_reg_load *load, const char *s) ovs_fatal(0, "%s: trailing garbage following destination", full_s); } - if (load->dst.n_bits < 64 && (load->value >> load->dst.n_bits) != 0) { + if (load->dst.n_bits < 64 && (value >> load->dst.n_bits) != 0) { ovs_fatal(0, "%s: value %"PRIu64" does not fit into %d bits", - full_s, load->value, load->dst.n_bits); + full_s, value, load->dst.n_bits); } + + memset(&load->subvalue, 0, sizeof &load->subvalue); + bitwise_copy(&value_be, sizeof value_be, 0, + &load->subvalue, sizeof load->subvalue, load->dst.ofs, + load->dst.n_bits); } /* nxm_format_reg_move(), nxm_format_reg_load(). */ @@ -1019,7 +1025,10 @@ nxm_format_reg_move(const struct ofpact_reg_move *move, struct ds *s) void nxm_format_reg_load(const struct ofpact_reg_load *load, struct ds *s) { - ds_put_format(s, "load:%#"PRIx64"->", load->value); + ovs_be64 value_be = htonll(0); + bitwise_copy(&load->subvalue, sizeof load->subvalue, load->dst.ofs, + &value_be, sizeof value_be, 0, load->dst.n_bits); + ds_put_format(s, "load:%#"PRIx64"->", ntohll(value_be)); mf_format_subfield(&load->dst, s); } @@ -1050,11 +1059,15 @@ nxm_reg_load_from_openflow(const struct nx_action_reg_load *narl, load->dst.field = mf_from_nxm_header(ntohl(narl->dst)); load->dst.ofs = nxm_decode_ofs(narl->ofs_nbits); load->dst.n_bits = nxm_decode_n_bits(narl->ofs_nbits); - load->value = ntohll(narl->value); + memset(&load->subvalue, 0, sizeof &load->subvalue); + bitwise_copy(&narl->value, sizeof narl->value, 0, + &load->subvalue, sizeof load->subvalue, load->dst.ofs, + load->dst.n_bits); /* Reject 'narl' if a bit numbered 'n_bits' or higher is set to 1 in * narl->value. */ - if (load->dst.n_bits < 64 && load->value >> load->dst.n_bits) { + if (load->dst.n_bits < 64 && + ntohll(narl->value) >> load->dst.n_bits) { return OFPERR_OFPBAC_BAD_ARGUMENT; } @@ -1103,7 +1116,9 @@ nxm_reg_load_to_nxast(const struct ofpact_reg_load *load, 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); - narl->value = htonll(load->value); + narl->value = htonll(0); + bitwise_copy(&load->subvalue, sizeof load->subvalue, load->dst.ofs, + &narl->value, sizeof narl->value, 0, load->dst.n_bits); } /* nxm_execute_reg_move(), nxm_execute_reg_load(). */ @@ -1126,20 +1141,18 @@ nxm_execute_reg_move(const struct ofpact_reg_move *move, void nxm_execute_reg_load(const struct ofpact_reg_load *load, struct flow *flow) { - nxm_reg_load(&load->dst, load->value, flow); + mf_write_subfield_flow(&load->dst, &load->subvalue, flow); } void nxm_reg_load(const struct mf_subfield *dst, uint64_t src_data, struct flow *flow) { - union mf_value dst_value; - union mf_value src_value; + union mf_subvalue src_subvalue; + ovs_be64 src_data_be = htonll(src_data); - mf_get_value(dst->field, flow, &dst_value); - src_value.be64 = htonll(src_data); - bitwise_copy(&src_value, sizeof src_value.be64, 0, - &dst_value, dst->field->n_bytes, dst->ofs, - dst->n_bits); - mf_set_flow_value(dst->field, &dst_value, flow); + bitwise_copy(&src_data_be, sizeof src_data_be, 0, + &src_subvalue, sizeof src_subvalue, 0, + sizeof src_data_be * 8); + mf_write_subfield_flow(dst, &src_subvalue, flow); } diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h index 4fc9094..58383e7 100644 --- a/lib/ofp-actions.h +++ b/lib/ofp-actions.h @@ -271,11 +271,11 @@ struct ofpact_reg_move { /* OFPACT_REG_LOAD. * - * Used for NXAST_REG_LOAD. */ + * Used for NXAST_REG_LOAD, OFPAT12_SET_FIELD. */ struct ofpact_reg_load { struct ofpact ofpact; struct mf_subfield dst; - uint64_t value; + union mf_subvalue subvalue; }; /* OFPACT_SET_TUNNEL. -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev