meta-flow: Make it simpler to expand mf_values in the future
authorMadhu Challa <challa@noironetworks.com>
Thu, 6 Nov 2014 18:55:08 +0000 (10:55 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 6 Nov 2014 18:55:14 +0000 (10:55 -0800)
Remove hard coded array index and make it dependent on the array size.

Signed-off-by: Madhu Challa <challa@noironetworks.com>
Co-authored-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/learn.c
lib/meta-flow.h

index e93015c..50ffd6f 100644 (file)
@@ -147,7 +147,8 @@ 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)) {
-                ofp_port_t port = u16_to_ofp(ntohs(value.be16[7]));
+                ovs_be16 *last_be16 = &value.be16[ARRAY_SIZE(value.be16) - 1];
+                ofp_port_t port = u16_to_ofp(ntohs(*last_be16));
 
                 if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX)
                     || port == OFPP_IN_PORT
@@ -209,7 +210,8 @@ learn_parse_load_immediate(const char *s, struct ofpact_learn_spec *spec)
         }
         s = arrow;
     } else {
-        imm.be64[1] = htonll(strtoull(s, (char **) &s, 0));
+        ovs_be64 *last_be64 = &imm.be64[ARRAY_SIZE(imm.be64) - 1];
+        *last_be64 = htonll(strtoull(s, (char **) &s, 0));
     }
 
     if (strncmp(s, "->", 2)) {
index 1659522..1646995 100644 (file)
@@ -1503,7 +1503,9 @@ union mf_value {
 };
 BUILD_ASSERT_DECL(sizeof(union mf_value) == 16);
 
+/* An all-1-bits mf_value.  Needs to be updated if struct mf_value grows.*/
 #define MF_EXACT_MASK_INITIALIZER { IN6ADDR_EXACT_INIT }
+BUILD_ASSERT_DECL(sizeof(union mf_value) == sizeof(struct in6_addr));
 
 /* Part of a field. */
 struct mf_subfield {