[ovs-dev] [PATCH 07/30] ofp-actions: Factor OFPACT_PADDED_MEMBERS out into a more general form.

Ben Pfaff blp at ovn.org
Mon Aug 8 07:44:46 UTC 2016


This makes it easier to reuse this idea elsewhere.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 include/openvswitch/ofp-actions.h | 14 +-------------
 include/openvswitch/util.h        | 22 +++++++++++++++++++++-
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h
index a0cefe3..310ec33 100644
--- a/include/openvswitch/ofp-actions.h
+++ b/include/openvswitch/ofp-actions.h
@@ -185,19 +185,7 @@ BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4);
 /* Alignment. */
 #define OFPACT_ALIGNTO 8
 #define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO)
-
-/* Expands to an anonymous union that contains:
- *
- *    - MEMBERS in a nested anonymous struct.
- *
- *    - An array as large as MEMBERS plus padding to a multiple of 8 bytes.
- *
- * The effect is to pad MEMBERS to a multiple of 8 bytes. */
-#define OFPACT_PADDED_MEMBERS(MEMBERS)                          \
-    union {                                                     \
-        struct { MEMBERS };                                     \
-        uint8_t pad[OFPACT_ALIGN(sizeof(struct { MEMBERS }))];  \
-    }
+#define OFPACT_PADDED_MEMBERS(MEMBERS) PADDED_MEMBERS(OFPACT_ALIGNTO, MEMBERS)
 
 /* Returns the ofpact following 'ofpact'. */
 static inline struct ofpact *
diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
index 363fa39..06bd2d0 100644
--- a/include/openvswitch/util.h
+++ b/include/openvswitch/util.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -162,6 +162,26 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
 /* Returns true if X is a power of 2, otherwise false. */
 #define IS_POW2(X) ((X) && !((X) & ((X) - 1)))
 
+/* Expands to an anonymous union that contains:
+ *
+ *    - MEMBERS in a nested anonymous struct.
+ *
+ *    - An array as large as MEMBERS plus padding to a multiple of UNIT bytes.
+ *
+ * The effect is to pad MEMBERS to a multiple of UNIT bytes.
+ *
+ * For example, the struct below is 8 bytes long, with 6 bytes of padding:
+ *
+ *     struct padded_struct {
+ *         PADDED_MEMBERS(8, uint8_t x; uint8_t y;);
+ *     };
+ */
+#define PADDED_MEMBERS(UNIT, MEMBERS)                               \
+    union {                                                         \
+        struct { MEMBERS };                                         \
+        uint8_t pad[ROUND_UP(sizeof(struct { MEMBERS }), UNIT)];    \
+    }
+
 static inline bool
 is_pow2(uintmax_t x)
 {
-- 
2.1.3




More information about the dev mailing list