Skip to content

Commit

Permalink
Lib: Ensure that all net_addr structures have the same alignment
Browse files Browse the repository at this point in the history
Also weaken the explicit alignment of net_addr to be u32, as VPN
is already u32-aligned.
  • Loading branch information
Ondrej Zajicek committed Dec 16, 2024
1 parent 34b7d77 commit 161aef3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/birdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "lib/alloca.h"
#include <stdarg.h>
#include <stdalign.h>

/* Ugly structure offset handling macros */

Expand Down
15 changes: 15 additions & 0 deletions lib/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ STATIC_ASSERT(sizeof(net_addr_ip6_sadr) == 40);
STATIC_ASSERT(sizeof(net_addr_mpls) == 8);
STATIC_ASSERT(sizeof(net_addr_aspa) == 8);

/* Ensure that all net_addr structures have the same alignment */
STATIC_ASSERT(alignof(net_addr_ip4) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_ip6) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_vpn4) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_vpn6) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_roa4) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_roa6) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_flow4) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_flow6) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_flow4) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_flow6) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_ip6_sadr) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_mpls) == alignof(net_addr));
STATIC_ASSERT(alignof(net_addr_aspa) == alignof(net_addr));


int
rd_format(const vpn_rd rd_, char *buf, int buflen)
Expand Down
2 changes: 1 addition & 1 deletion lib/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct net_addr {
u8 pxlen;
u16 length;
u8 data[20];
u64 align[0];
u32 align[0];
} net_addr;

typedef struct net_addr_ip4 {
Expand Down

0 comments on commit 161aef3

Please sign in to comment.