From 7b51295530c5a9b708ceffc7a557e8dc110f9a19 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 15 Jul 2016 14:14:21 -0700 Subject: [PATCH] ofp-actions: Factor OFPACT_PADDED_MEMBERS out into a more general form. This makes it easier to reuse this idea elsewhere. Signed-off-by: Ben Pfaff Acked-by: Ryan Moats --- 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 a0cefe322..310ec335b 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 363fa39b6..06bd2d0eb 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.39.5