summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/dhcp-identifier.c
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2015-11-16 09:21:20 +0100
committerDaniel Mack <daniel@zonque.org>2015-11-16 15:20:29 +0100
commitdbe81cbd2a93088236a2e4e41eeb33378940f7b9 (patch)
tree8aec120af6f424803074d35827fbfb5048d8a9cf /src/libsystemd-network/dhcp-identifier.c
parent8dd85afe761885a9c47173cdafd1b7f9b36d08e6 (diff)
siphash24: change result argument to uint64_t
Change the "out" parameter from uint8_t[8] to uint64_t. On architectures which enforce pointer alignment this fixes crashes when we previously cast an unaligned array to uint64_t*, and on others this should at least improve performance as the compiler now aligns these properly. This also simplifies the code in most cases by getting rid of typecasts. The only place which we can't change is struct duid's en.id, as that is _packed_ and public API, so we can't enforce alignment of the "id" field and have to use memcpy instead.
Diffstat (limited to 'src/libsystemd-network/dhcp-identifier.c')
-rw-r--r--src/libsystemd-network/dhcp-identifier.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libsystemd-network/dhcp-identifier.c b/src/libsystemd-network/dhcp-identifier.c
index 51ee7bcce4..368525c40a 100644
--- a/src/libsystemd-network/dhcp-identifier.c
+++ b/src/libsystemd-network/dhcp-identifier.c
@@ -35,6 +35,7 @@
int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
sd_id128_t machine_id;
+ uint64_t hash;
int r;
assert(duid);
@@ -50,8 +51,9 @@ int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
*len = sizeof(duid->type) + sizeof(duid->en);
/* a bit of snake-oil perhaps, but no need to expose the machine-id
- directly */
- siphash24(duid->en.id, &machine_id, sizeof(machine_id), HASH_KEY.bytes);
+ directly; duid->en.id might not be aligned, so we need to copy */
+ siphash24(&hash, &machine_id, sizeof(machine_id), HASH_KEY.bytes);
+ memcpy(duid->en.id, &hash, sizeof(duid->en.id));
return 0;
}
@@ -84,10 +86,10 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_i
}
if (name)
- siphash24((uint8_t*)&id, name, strlen(name), HASH_KEY.bytes);
+ siphash24(&id, name, strlen(name), HASH_KEY.bytes);
else
/* fall back to MAC address if no predictable name available */
- siphash24((uint8_t*)&id, mac, mac_len, HASH_KEY.bytes);
+ siphash24(&id, mac, mac_len, HASH_KEY.bytes);
/* fold into 32 bits */
unaligned_write_be32(_id, (id & 0xffffffff) ^ (id >> 32));