summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2016-01-22 20:57:34 +0000
committerBen Hutchings <ben@decadent.org.uk>2016-01-28 15:48:06 +0000
commit687b3c65c0460dd8c4ba7e63e3ae0ab20836e6e8 (patch)
tree2b54573e649124945a74665cd3b9c38dd5d052a3
parent8a8005f7ca8973702b36e711993bfff89ca9600c (diff)
downloadodhcp6c-687b3c65c0460dd8c4ba7e63e3ae0ab20836e6e8.tar.gz
Fix alignment of buffers in ra_process and dhcpv6_request
The packet buffer needs to be 32-bit aligned to ensure that the various 32-bit fields we pick out are naturally aligned. The control message buffers needs to be naturally aligned for struct cmsghdr. Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r--src/dhcpv6.c4
-rw-r--r--src/odhcp6c.h1
-rw-r--r--src/ra.c3
3 files changed, 6 insertions, 2 deletions
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index e27d899..8a1231d 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -577,7 +577,9 @@ int dhcpv6_request(enum dhcpv6_msg type)
// Receive rounds
for (; len < 0 && (round_start < round_end);
round_start = odhcp6c_get_milli_time()) {
- uint8_t buf[1536], cmsg_buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
+ uint8_t buf[1536];
+ uint8_t cmsg_buf[CMSG_SPACE(sizeof(struct in6_pktinfo))]
+ __aligned(__alignof__(struct cmsghdr));
struct iovec iov = {buf, sizeof(buf)};
struct sockaddr_in6 addr;
struct msghdr msg = {.msg_name = &addr, .msg_namelen = sizeof(addr),
diff --git a/src/odhcp6c.h b/src/odhcp6c.h
index 98d91dd..08a816f 100644
--- a/src/odhcp6c.h
+++ b/src/odhcp6c.h
@@ -18,6 +18,7 @@
#define _unused __attribute__((unused))
#define _packed __attribute__((packed))
+#define __aligned(n) __attribute__((aligned(n)))
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
diff --git a/src/ra.c b/src/ra.c
index 2d442f6..dd5962a 100644
--- a/src/ra.c
+++ b/src/ra.c
@@ -274,7 +274,8 @@ bool ra_process(void)
{
bool found = false;
bool changed = false;
- uint8_t buf[1500], cmsg_buf[128];
+ uint8_t buf[1500] __aligned(4);
+ uint8_t cmsg_buf[128] __aligned(__alignof__(struct cmsghdr));
struct nd_router_advert *adv = (struct nd_router_advert*)buf;
struct odhcp6c_entry *entry = alloca(sizeof(*entry) + 256);
const struct in6_addr any = IN6ADDR_ANY_INIT;