With the bug fix below,

Acked-by: Jarno Rajahalme <ja...@ovn.org>

> On Jan 18, 2016, at 11:27 PM, Ben Pfaff <b...@ovn.org> wrote:
> 
> This will have additional users in later commits.
> 
> Signed-off-by: Ben Pfaff <b...@ovn.org>
> ---
> lib/ofp-prop.c | 22 ++++++++++++++++++++++
> lib/ofp-prop.h |  1 +
> lib/ofp-util.c | 20 ++++++--------------
> 3 files changed, 29 insertions(+), 14 deletions(-)
> 
> diff --git a/lib/ofp-prop.c b/lib/ofp-prop.c
> index 76031b6..1641a39 100644
> --- a/lib/ofp-prop.c
> +++ b/lib/ofp-prop.c
> @@ -261,6 +261,28 @@ ofpprop_put(struct ofpbuf *msg, uint64_t type, const 
> void *value, size_t len)
>     ofpprop_end(msg, start_ofs);
> }
> 
> +/* Adds a property with the given 'type' to 'msg', consisting of a struct
> + * ofp_prop_header followed by enough zero bytes to total 'len' bytes, 
> followed
> + * by padding to bring the property up to a multiple of 8 bytes.  Returns the
> + * property header. */
> +void *
> +ofpprop_put_zeros(struct ofpbuf *msg, uint64_t type, size_t len)
> +{
> +    void *header = ofpbuf_put_zeros(msg, ROUND_UP(len, 8));
> +    if (!ofpprop_is_experimenter(type)) {
> +        struct ofp_prop_header *oph = header;
> +        oph->type = htons(type);
> +        oph->len = htons(len);
> +    } else {
> +        struct ofp_prop_experimenter *ope = header;
> +        ope->type = htons(0xffff);
> +        ope->len = htons(12);

No ‘len’ here?

> +        ope->experimenter = htonl(ofpprop_type_to_experimenter(type));
> +        ope->exp_type = htonl(ofpprop_type_to_exp_id(type));
> +    }
> +    return header;
> +}
> +
> /* Adds a property with the given 'type' and 16-bit 'value' to 'msg'. */
> void
> ofpprop_put_be16(struct ofpbuf *msg, uint64_t type, ovs_be16 value)
> diff --git a/lib/ofp-prop.h b/lib/ofp-prop.h
> index 7cd107c..db29650 100644
> --- a/lib/ofp-prop.h
> +++ b/lib/ofp-prop.h
> @@ -85,6 +85,7 @@ enum ofperr ofpprop_parse_uuid(const struct ofpbuf *, 
> struct uuid *);
> /* Serializing properties. */
> void ofpprop_put(struct ofpbuf *, uint64_t type,
>                  const void *value, size_t len);
> +void *ofpprop_put_zeros(struct ofpbuf *, uint64_t type, size_t len);
> void ofpprop_put_be16(struct ofpbuf *, uint64_t type, ovs_be16 value);
> void ofpprop_put_be32(struct ofpbuf *, uint64_t type, ovs_be32 value);
> void ofpprop_put_be64(struct ofpbuf *, uint64_t type, ovs_be64 value);
> diff --git a/lib/ofp-util.c b/lib/ofp-util.c
> index c813afd..1225664 100644
> --- a/lib/ofp-util.c
> +++ b/lib/ofp-util.c
> @@ -3868,9 +3868,7 @@ ofputil_put_ofp14_port(const struct ofputil_phy_port 
> *pp,
>     op->config = htonl(pp->config & OFPPC11_ALL);
>     op->state = htonl(pp->state & OFPPS11_ALL);
> 
> -    eth = ofpbuf_put_zeros(b, sizeof *eth);
> -    eth->type = htons(OFPPDPT14_ETHERNET);
> -    eth->length = htons(sizeof *eth);
> +    eth = ofpprop_put_zeros(b, OFPPDPT14_ETHERNET, sizeof *eth);
>     eth->curr = netdev_port_features_to_ofp11(pp->curr);
>     eth->advertised = netdev_port_features_to_ofp11(pp->advertised);
>     eth->supported = netdev_port_features_to_ofp11(pp->supported);
> @@ -5013,9 +5011,7 @@ ofputil_append_table_desc_reply(const struct 
> ofputil_table_desc *td,
>     if (td->vacancy == OFPUTIL_TABLE_VACANCY_ON) {
>         struct ofp14_table_mod_prop_vacancy *otv;
> 
> -        otv = ofpbuf_put_zeros(reply, sizeof *otv);
> -        otv->type = htons(OFPTMPT14_VACANCY);
> -        otv->length = htons(sizeof *otv);
> +        otv = ofpprop_put_zeros(reply, OFPTMPT14_VACANCY, sizeof *otv);
>         otv->vacancy_down = td->table_vacancy.vacancy_down;
>         otv->vacancy_up = td->table_vacancy.vacancy_up;
>         otv->vacancy = td->table_vacancy.vacancy;
> @@ -5279,7 +5275,6 @@ ofputil_encode_table_mod(const struct ofputil_table_mod 
> *tm,
>     case OFP14_VERSION:
>     case OFP15_VERSION: {
>         struct ofp14_table_mod *otm;
> -        struct ofp14_table_mod_prop_vacancy *otv;
> 
>         b = ofpraw_alloc(OFPRAW_OFPT14_TABLE_MOD, ofp_version, 0);
>         otm = ofpbuf_put_zeros(b, sizeof *otm);
> @@ -5291,9 +5286,9 @@ ofputil_encode_table_mod(const struct ofputil_table_mod 
> *tm,
>             ofpprop_put_u32(b, OFPTMPT14_EVICTION, tm->eviction_flags);
>         }
>         if (tm->vacancy == OFPUTIL_TABLE_VACANCY_ON) {
> -            otv = ofpbuf_put_zeros(b, sizeof *otv);
> -            otv->type = htons(OFPTMPT14_VACANCY);
> -            otv->length = htons(sizeof *otv);
> +            struct ofp14_table_mod_prop_vacancy *otv;
> +
> +            otv = ofpprop_put_zeros(b, OFPTMPT14_VACANCY, sizeof *otv);
>             otv->vacancy_down = tm->table_vacancy.vacancy_down;
>             otv->vacancy_up = tm->table_vacancy.vacancy_up;
>         }
> @@ -6961,10 +6956,7 @@ ofputil_append_ofp14_port_stats(const struct 
> ofputil_port_stats *ops,
>     ps14->rx_errors = htonll(ops->stats.rx_errors);
>     ps14->tx_errors = htonll(ops->stats.tx_errors);
> 
> -    eth = ofpbuf_put_uninit(reply, sizeof *eth);
> -    eth->type = htons(OFPPSPT14_ETHERNET);
> -    eth->length = htons(sizeof *eth);
> -    memset(eth->pad, 0, sizeof eth->pad);
> +    eth = ofpprop_put_zeros(reply, OFPPSPT14_ETHERNET, sizeof *eth);
>     eth->rx_frame_err = htonll(ops->stats.rx_frame_errors);
>     eth->rx_over_err = htonll(ops->stats.rx_over_errors);
>     eth->rx_crc_err = htonll(ops->stats.rx_crc_errors);
> -- 
> 2.1.3
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to