From 161aef353a56532752d5d0f97e432c0915058050 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Mon, 16 Dec 2024 18:56:30 +0100 Subject: [PATCH] Lib: Ensure that all net_addr structures have the same alignment Also weaken the explicit alignment of net_addr to be u32, as VPN is already u32-aligned. --- lib/birdlib.h | 1 + lib/net.c | 15 +++++++++++++++ lib/net.h | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/birdlib.h b/lib/birdlib.h index 0779655e..9bbffe02 100644 --- a/lib/birdlib.h +++ b/lib/birdlib.h @@ -11,6 +11,7 @@ #include "lib/alloca.h" #include +#include /* Ugly structure offset handling macros */ diff --git a/lib/net.c b/lib/net.c index e83cdce7..64cf9e04 100644 --- a/lib/net.c +++ b/lib/net.c @@ -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) diff --git a/lib/net.h b/lib/net.h index fe5c0d8c..a1fd0291 100644 --- a/lib/net.h +++ b/lib/net.h @@ -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 {