This makes access to the least-significant bits more convenient. This commit simplifies a few existing cases; later commits will make more use of this feature.
Signed-off-by: Ben Pfaff <b...@nicira.com> --- lib/learn.c | 6 ++---- lib/meta-flow.h | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/learn.c b/lib/learn.c index 71c9780..dc6d095 100644 --- a/lib/learn.c +++ b/lib/learn.c @@ -148,8 +148,7 @@ learn_execute(const struct ofpact_learn *learn, const struct flow *flow, case NX_LEARN_DST_OUTPUT: if (spec->n_bits <= 16 || is_all_zeros(value.u8, sizeof value - 2)) { - ovs_be16 *last_be16 = &value.be16[ARRAY_SIZE(value.be16) - 1]; - ofp_port_t port = u16_to_ofp(ntohs(*last_be16)); + ofp_port_t port = u16_to_ofp(ntohll(value.integer)); if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX) || port == OFPP_IN_PORT @@ -211,8 +210,7 @@ learn_parse_load_immediate(const char *s, struct ofpact_learn_spec *spec) } s = arrow; } else { - ovs_be64 *last_be64 = &imm.be64[ARRAY_SIZE(imm.be64) - 1]; - *last_be64 = htonll(strtoull(s, (char **) &s, 0)); + imm.integer = htonll(strtoull(s, (char **) &s, 0)); } if (strncmp(s, "->", 2)) { diff --git a/lib/meta-flow.h b/lib/meta-flow.h index d29cc64..be3ed1b 100644 --- a/lib/meta-flow.h +++ b/lib/meta-flow.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2014 Nicira, Inc. + * Copyright (c) 2011, 2012, 2013, 2014, 2015 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1567,10 +1567,26 @@ struct mf_subfield { * value" contains NXM_OF_VLAN_TCI[0..11], then one could access the * corresponding data in value.be16[7] as the bits in the mask htons(0xfff). */ union mf_subvalue { + /* Access to full data. */ uint8_t u8[16]; ovs_be16 be16[8]; ovs_be32 be32[4]; ovs_be64 be64[2]; + + /* Convenient access to just least-significant bits in various forms. */ + struct { + ovs_be64 dummy_integer; + ovs_be64 integer; + }; + struct { + uint8_t dummy_mac[10]; + uint8_t mac[6]; + }; + struct { + ovs_be32 dummy_ipv4[3]; + ovs_be32 ipv4; + }; + struct in6_addr ipv6; }; BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof (union mf_subvalue)); -- 2.1.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev