[ovs-dev] [PATCH ovn 1/5] meta-flow: Add convenience members to union mf_subvalue.

Ben Pfaff blp at nicira.com
Tue Mar 31 03:57:19 UTC 2015


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 <blp at nicira.com>
---
 lib/learn.c     |  6 ++----
 lib/meta-flow.h | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/lib/learn.c b/lib/learn.c
index 99d56e6..7ed7884 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 0e09036..de02d1a 100644
--- a/lib/meta-flow.h
+++ b/lib/meta-flow.h
@@ -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




More information about the dev mailing list