[ovs-dev] [PATCH 1/2] ofp-actions: Make struct ofpact constant size across implementations.

Alin Serdean aserdean at cloudbasesolutions.com
Tue Aug 12 18:59:48 UTC 2014

Acked-by : Alin Serdean <aserdean at cloudbasesolutions.com>

-----Mesaj original-----
De la: Ben Pfaff [mailto:blp at nicira.com] 
Trimis: Tuesday, August 12, 2014 9:44 PM
Către: dev at openvswitch.org
Cc: Ben Pfaff; Alin Serdean
Subiect: [PATCH 1/2] ofp-actions: Make struct ofpact constant size across implementations.

Before commit c2d936a44fa6 (ofp-actions: Centralize all OpenFlow action code for maintainability.), struct ofpact was 4 bytes with GCC and Clang, and 12 bytes with other compilers.  That commit changed struct ofpact so that it remained 4 bytes with GCC and Clang but shrank to 8 bytes on other compilers.  An unexpected side effect of that change was that the size of the pad[] array in struct ofpact_nest shrank to 0 bytes, because that array padded to a multiple of 8 bytes.  MSVC does not support 0-element arrays, so this caused a build failure.

This commit fixes the problem by changing struct ofpact so that it is 4 bytes with every compiler.

Reported-by: Alin Serdean <aserdean at cloudbasesolutions.com>
Signed-off-by: Ben Pfaff <blp at nicira.com>
 lib/compiler.h    |    1 +
 lib/ofp-actions.h |   12 ++++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/compiler.h b/lib/compiler.h index cfe9066..e8bf119 100644
--- a/lib/compiler.h
+++ b/lib/compiler.h
@@ -169,6 +169,7 @@
  * or otherwise exposed outside of a single process. */  #if __GNUC__ && !__CHECKER__  #define OVS_PACKED_ENUM __attribute__((__packed__))
diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h index 0f1ea3f..5436f24 100644
--- a/lib/ofp-actions.h
+++ b/lib/ofp-actions.h
@@ -157,16 +157,20 @@ enum {
  *       code to translate the ofpact to OpenFlow must tolerate this case.)
 struct ofpact {
+    /* We want the space advantage of an 8-bit type here on every
+     * implementation, without giving up the advantage of having a useful type
+     * on implementations that support packed enums. */ #ifdef 
     enum ofpact_type type;      /* OFPACT_*. */
+    uint8_t type;               /* OFPACT_* */
     uint8_t raw;                /* Original type when added, if any. */
     uint16_t len;               /* Length of the action, in bytes, including
                                  * struct ofpact, excluding padding. */  };
-#ifdef __GNUC__
-/* Make sure that OVS_PACKED_ENUM really worked. */  BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4); -#endif
 /* Alignment. */

More information about the dev mailing list