This patch also updates nxm_check_reg_move() to use nxm_src_check() and nxm_dst_check(). A user outside of nxm-match will be added in a future patch. --- lib/nx-match.c | 48 +++++++++++++++++++++++++++++++----------------- lib/nx-match.h | 2 ++ 2 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/lib/nx-match.c b/lib/nx-match.c index ecc284e..e94be95 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -1191,28 +1191,42 @@ int nxm_check_reg_move(const struct nx_action_reg_move *action, const struct flow *flow) { - const struct nxm_field *src; - const struct nxm_field *dst; + ovs_be16 src_ofs_nbits; + ovs_be16 dst_ofs_nbits; + uint16_t n_bits; + int error; - if (action->n_bits == htons(0)) { - return BAD_ARGUMENT; - } + n_bits = ntohs(action->n_bits); + src_ofs_nbits = nxm_encode_ofs_nbits(ntohs(action->src_ofs), n_bits); + dst_ofs_nbits = nxm_encode_ofs_nbits(ntohs(action->dst_ofs), n_bits); - src = nxm_field_lookup(ntohl(action->src)); - if (!field_ok(src, flow, ntohs(action->src_ofs) + ntohs(action->n_bits))) { - return BAD_ARGUMENT; - } + error = nxm_src_check(action->src, src_ofs_nbits, 1, flow); + error = error ? error : nxm_dst_check(action->dst, dst_ofs_nbits, 1, flow); + return error; +} - dst = nxm_field_lookup(ntohl(action->dst)); - if (!field_ok(dst, flow, ntohs(action->dst_ofs) + ntohs(action->n_bits))) { - return BAD_ARGUMENT; - } +/* Given a flow, checks that the source field represented by 'src_header' and + * 'ofs_nbits' is valid, and contains at least 'min_n_bits' bits of data. */ +int +nxm_src_check(ovs_be32 src_header, ovs_be16 ofs_nbits, size_t min_n_bits, + const struct flow *flow) +{ + const struct nxm_field *src; + int ofs, n_bits; - if (!dst->writable) { - return BAD_ARGUMENT; + ofs = nxm_decode_ofs(ofs_nbits); + n_bits = nxm_decode_n_bits(ofs_nbits); + src = nxm_field_lookup(ntohl(src_header)); + + if (!field_ok(src, flow, ofs + n_bits)) { + VLOG_WARN_RL(&rl, "invalid source field"); + } else if (n_bits < min_n_bits) { + VLOG_WARN_RL(&rl, "insufficient bits in source field"); + } else { + return 0; } - return 0; + return BAD_ARGUMENT; } /* Given a flow, checks that the destination field represented by 'dst_header' diff --git a/lib/nx-match.h b/lib/nx-match.h index 5365cca..264a65a 100644 --- a/lib/nx-match.h +++ b/lib/nx-match.h @@ -49,6 +49,8 @@ void nxm_format_reg_load(const struct nx_action_reg_load *, struct ds *); int nxm_check_reg_move(const struct nx_action_reg_move *, const struct flow *); int nxm_check_reg_load(const struct nx_action_reg_load *, const struct flow *); +int nxm_src_check(ovs_be32 src, ovs_be16 ofs_nbits, size_t min_n_bits, + const struct flow *); int nxm_dst_check(ovs_be32 dst, ovs_be16 ofs_nbits, size_t min_n_bits, const struct flow *); -- 1.7.6 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev