This seems to me to better encapsulate the inherent ugliness.
---
 lib/dpif-netdev.c |    6 +++---
 lib/odp-util.h    |   11 ++++++-----
 ofproto/ofproto.c |   12 ++++++------
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 035ceae..762d24b 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -872,7 +872,7 @@ struct dp_netdev_flow_state {
     uint32_t bucket;
     uint32_t offset;
     struct nlattr *actions;
-    uint32_t keybuf[ODPUTIL_FLOW_KEY_U32S];
+    struct odputil_keybuf keybuf;
     struct dpif_flow_stats stats;
 };
 
@@ -909,9 +909,9 @@ dpif_netdev_flow_dump_next(const struct dpif *dpif, void 
*state_,
     if (key) {
         struct ofpbuf buf;
 
-        ofpbuf_use_stack(&buf, state->keybuf, sizeof state->keybuf);
+        ofpbuf_use_stack(&buf, &state->keybuf, sizeof state->keybuf);
         odp_flow_key_from_flow(&buf, &flow->key);
-        assert(buf.base == state->keybuf);
+        assert(buf.base == &state->keybuf);
 
         *key = buf.data;
         *key_len = buf.size;
diff --git a/lib/odp-util.h b/lib/odp-util.h
index 4020660..a88c7ee 100644
--- a/lib/odp-util.h
+++ b/lib/odp-util.h
@@ -86,11 +86,12 @@ void format_odp_actions(struct ds *, const struct nlattr 
*odp_actions,
  * key types are added. */
 BUILD_ASSERT_DECL(__ODP_KEY_ATTR_MAX == 14);
 
-/* We allocate temporary on-stack buffers for flow keys as arrays of uint32_t
- * to ensure proper 32-bit alignment for Netlink attributes.  (An array of
- * "struct nlattr" might not, in theory, be sufficiently aligned because it
- * only contains 16-bit types.) */
-#define ODPUTIL_FLOW_KEY_U32S DIV_ROUND_UP(ODPUTIL_FLOW_KEY_BYTES, 4)
+/* A buffer with sufficient size and alignment to hold an nlattr-formatted flow
+ * key.  An array of "struct nlattr" might not, in theory, be sufficiently
+ * aligned because it only contains 16-bit types. */
+struct odputil_keybuf {
+    uint32_t keybuf[DIV_ROUND_UP(ODPUTIL_FLOW_KEY_BYTES, 4)];
+};
 
 void odp_flow_key_format(const struct nlattr *, size_t, struct ds *);
 
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 2efb03a..d1ac197 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -2332,7 +2332,7 @@ facet_put__(struct ofproto *ofproto, struct facet *facet,
             const struct nlattr *actions, size_t actions_len,
             struct dpif_flow_stats *stats)
 {
-    uint32_t keybuf[ODPUTIL_FLOW_KEY_U32S];
+    struct odputil_keybuf keybuf;
     enum dpif_flow_put_flags flags;
     struct ofpbuf key;
 
@@ -2343,9 +2343,9 @@ facet_put__(struct ofproto *ofproto, struct facet *facet,
         facet->dp_byte_count = 0;
     }
 
-    ofpbuf_use_stack(&key, keybuf, sizeof keybuf);
+    ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
     odp_flow_key_from_flow(&key, &facet->flow);
-    assert(key.base == keybuf);
+    assert(key.base == &keybuf);
 
     return dpif_flow_put(ofproto->dpif, flags, key.data, key.size,
                          actions, actions_len, stats);
@@ -2389,13 +2389,13 @@ static void
 facet_uninstall(struct ofproto *p, struct facet *facet)
 {
     if (facet->installed) {
-        uint32_t keybuf[ODPUTIL_FLOW_KEY_U32S];
+        struct odputil_keybuf keybuf;
         struct dpif_flow_stats stats;
         struct ofpbuf key;
 
-        ofpbuf_use_stack(&key, keybuf, sizeof keybuf);
+        ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
         odp_flow_key_from_flow(&key, &facet->flow);
-        assert(key.base == keybuf);
+        assert(key.base == &keybuf);
 
         if (!dpif_flow_del(p->dpif, key.data, key.size, &stats)) {
             facet_update_stats(p, facet, &stats);
-- 
1.7.1


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

Reply via email to