From b0332a75ccf3a7323dbc06c3fbe1728cbdc2914c Mon Sep 17 00:00:00 2001 From: Ken Keys Date: Tue, 28 May 2019 14:03:36 -0700 Subject: [PATCH] Fix size/alignment of bgpstream_pfx_t --- lib/utils/bgpstream_utils_pfx.h | 76 +++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/lib/utils/bgpstream_utils_pfx.h b/lib/utils/bgpstream_utils_pfx.h index 2747ebdc..56ee3ec4 100644 --- a/lib/utils/bgpstream_utils_pfx.h +++ b/lib/utils/bgpstream_utils_pfx.h @@ -53,42 +53,51 @@ * * @{ */ +#define BS_PFX_OFFSET \ + offsetof(struct {uint8_t l; uint8_t m; bgpstream_ip_addr_t a;}, a) + /** An IPv4 BGP Stream Prefix */ typedef struct struct_bgpstream_ipv4_pfx_t { - /** Length of the prefix mask */ - uint8_t mask_len; + union { // anonymous + uint8_t _dummy[BS_PFX_OFFSET]; // force alignment of address - /** Indicates what type of matches are allowed with this prefix. - * For filtering purposes only. - */ - uint8_t allowed_matches; + struct { + /** Length of the prefix mask */ + uint8_t mask_len; - union { - /** The address */ - bgpstream_ipv4_addr_t address; - max_align_t _dummy; // force alignment + /** Indicates what type of matches are allowed with this prefix. + * For filtering purposes only. + */ + uint8_t allowed_matches; + }; }; + /** The address */ + bgpstream_ipv4_addr_t address; + } bgpstream_ipv4_pfx_t; /** An IPv6 BGP Stream Prefix */ typedef struct struct_bgpstream_ipv6_pfx_t { - /** Length of the prefix mask */ - uint8_t mask_len; + union { // anonymous + uint8_t _dummy[BS_PFX_OFFSET]; // force alignment of address - /** Indicates what type of matches are allowed with this prefix. - * For filtering purposes only. - */ - uint8_t allowed_matches; + struct { + /** Length of the prefix mask */ + uint8_t mask_len; - union { - /** The address */ - bgpstream_ipv6_addr_t address; - max_align_t _dummy; // force alignment + /** Indicates what type of matches are allowed with this prefix. + * For filtering purposes only. + */ + uint8_t allowed_matches; + }; }; + /** The address */ + bgpstream_ipv6_addr_t address; + } bgpstream_ipv6_pfx_t; /** Generic BGP Stream Prefix @@ -102,19 +111,22 @@ typedef union union_bgpstream_pfx_t { /// Generic variant struct { - /** Length of the prefix mask */ - uint8_t mask_len; - - /** Indicates what type of matches are allowed with this prefix. - * For filtering purposes only. - */ - uint8_t allowed_matches; - - union { - /** The address */ - bgpstream_ip_addr_t address; - max_align_t _dummy; // force alignment + union { // anonymous + uint8_t _dummy[BS_PFX_OFFSET]; // force alignment of address + + struct { + /** Length of the prefix mask */ + uint8_t mask_len; + + /** Indicates what type of matches are allowed with this prefix. + * For filtering purposes only. + */ + uint8_t allowed_matches; + }; }; + + /** The address */ + bgpstream_ip_addr_t address; }; /// IPv4 variant, iff address.version == BGPSTREAM_ADDR_VERSION_IPV4