summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2008-05-08 14:15:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2008-05-08 14:15:41 +0000
commit1a9fecbc62b0b2f3e38e57c4afa62f92702e6ec2 (patch)
tree1839a10a2adc540ab57105f968d199a1c0a16cf7 /usr.sbin
parentf14647e73b76f146d0c1698e205a0a4b5f3e5714 (diff)
Insert pad blocks after sub-messages to keep the structures aligned to
16 byte boundaries for maximum portability (somewhat similar to CMSG's) ok beck
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/dhcpd/sync.c15
-rw-r--r--usr.sbin/dhcpd/sync.h7
2 files changed, 18 insertions, 4 deletions
diff --git a/usr.sbin/dhcpd/sync.c b/usr.sbin/dhcpd/sync.c
index da33953cd47..03814c339e2 100644
--- a/usr.sbin/dhcpd/sync.c
+++ b/usr.sbin/dhcpd/sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sync.c,v 1.3 2008/05/08 07:28:08 beck Exp $ */
+/* $OpenBSD: sync.c,v 1.4 2008/05/08 14:15:40 deraadt Exp $ */
/*
* Copyright (c) 2008 Bob Beck <beck@openbsd.org>
@@ -411,16 +411,22 @@ sync_lease(struct lease *lease)
struct dhcp_synchdr hdr;
struct dhcp_synctlv_lease ld;
struct dhcp_synctlv_hdr end;
+ char pad[DHCP_ALIGNBYTES];
+ u_int16_t leaselen, padlen;
int i = 0;
HMAC_CTX ctx;
u_int hmac_len;
bzero(&hdr, sizeof(hdr));
bzero(&ld, sizeof(ld));
+ bzero(&pad, sizeof(pad));
HMAC_CTX_init(&ctx);
HMAC_Init(&ctx, sync_key, strlen(sync_key), EVP_sha1());
+ leaselen = sizeof(ld);
+ padlen = DHCP_ALIGN(leaselen) - leaselen;
+
/* Add DHCP sync packet header */
hdr.sh_version = DHCP_SYNC_VERSION;
hdr.sh_af = AF_INET;
@@ -433,7 +439,7 @@ sync_lease(struct lease *lease)
/* Add single DHCP sync address entry */
ld.type = htons(DHCP_SYNC_LEASE);
- ld.length = htons(sizeof(ld));
+ ld.length = htons(leaselen + padlen);
ld.timestamp = htonl(lease->timestamp);
ld.starts = htonl(lease->starts);
ld.ends = htonl(lease->ends);
@@ -452,6 +458,11 @@ sync_lease(struct lease *lease)
HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
i++;
+ iov[i].iov_base = pad;
+ iov[i].iov_len = padlen;
+ HMAC_Update(&ctx, iov[i].iov_base, iov[i].iov_len);
+ i++;
+
/* Add end marker */
end.st_type = htons(DHCP_SYNC_END);
end.st_length = htons(sizeof(end));
diff --git a/usr.sbin/dhcpd/sync.h b/usr.sbin/dhcpd/sync.h
index 28371e8e103..3f3daeafccf 100644
--- a/usr.sbin/dhcpd/sync.h
+++ b/usr.sbin/dhcpd/sync.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sync.h,v 1.2 2008/05/08 05:38:26 beck Exp $ */
+/* $OpenBSD: sync.h,v 1.3 2008/05/08 14:15:40 deraadt Exp $ */
/*
* Copyright (c) 2008, Bob Beck <beck@openbsd.org>
@@ -39,13 +39,16 @@
#define DHCP_SYNC_MAXSIZE 1408
#define DHCP_SYNC_KEY "/var/db/dhcpd.key"
+#define DHCP_ALIGNBYTES (15)
+#define DHCP_ALIGN(p) (((u_int)(p) + DHCP_ALIGNBYTES) &~ DHCP_ALIGNBYTES)
+
struct dhcp_synchdr {
u_int8_t sh_version;
u_int8_t sh_af;
u_int16_t sh_length;
u_int32_t sh_counter;
u_int8_t sh_hmac[DHCP_SYNC_HMAC_LEN];
- u_int16_t sh_pad[2];
+ u_int8_t sh_pad[4];
} __packed;
struct dhcp_synctlv_hdr {