Skip to content

Commit

Permalink
Merge pull request #94 from CAIDA/addr
Browse files Browse the repository at this point in the history
Fix size/alignment of bgpstream_pfx_t
  • Loading branch information
alistairking authored May 28, 2019
2 parents 9d8479e + b0332a7 commit 2e0b185
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions lib/utils/bgpstream_utils_pfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2e0b185

Please sign in to comment.