diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2015-11-16 09:21:20 +0100 |
---|---|---|
committer | Daniel Mack <daniel@zonque.org> | 2015-11-16 15:20:29 +0100 |
commit | dbe81cbd2a93088236a2e4e41eeb33378940f7b9 (patch) | |
tree | 8aec120af6f424803074d35827fbfb5048d8a9cf /src/network | |
parent | 8dd85afe761885a9c47173cdafd1b7f9b36d08e6 (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/network')
-rw-r--r-- | src/network/networkd-ipv4ll.c | 6 | ||||
-rw-r--r-- | src/network/networkd-netdev.c | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/network/networkd-ipv4ll.c b/src/network/networkd-ipv4ll.c index ed0d861e7a..506654b5d7 100644 --- a/src/network/networkd-ipv4ll.c +++ b/src/network/networkd-ipv4ll.c @@ -201,7 +201,7 @@ static void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata){ } int ipv4ll_configure(Link *link) { - uint8_t seed[8]; + uint64_t seed; int r; assert(link); @@ -215,11 +215,11 @@ int ipv4ll_configure(Link *link) { } if (link->udev_device) { - r = net_get_unique_predictable_data(link->udev_device, seed); + r = net_get_unique_predictable_data(link->udev_device, &seed); if (r >= 0) { assert_cc(sizeof(unsigned) <= 8); - r = sd_ipv4ll_set_address_seed(link->ipv4ll, *(unsigned *)seed); + r = sd_ipv4ll_set_address_seed(link->ipv4ll, (unsigned)seed); if (r < 0) return r; } diff --git a/src/network/networkd-netdev.c b/src/network/networkd-netdev.c index dd0b400c6a..081e299d82 100644 --- a/src/network/networkd-netdev.c +++ b/src/network/networkd-netdev.c @@ -411,7 +411,7 @@ int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *message) { int netdev_get_mac(const char *ifname, struct ether_addr **ret) { _cleanup_free_ struct ether_addr *mac = NULL; - uint8_t result[8]; + uint64_t result; size_t l, sz; uint8_t *v; int r; @@ -438,10 +438,10 @@ int netdev_get_mac(const char *ifname, struct ether_addr **ret) { /* Let's hash the host machine ID plus the container name. We * use a fixed, but originally randomly created hash key here. */ - siphash24(result, v, sz, HASH_KEY.bytes); + siphash24(&result, v, sz, HASH_KEY.bytes); assert_cc(ETH_ALEN <= sizeof(result)); - memcpy(mac->ether_addr_octet, result, ETH_ALEN); + memcpy(mac->ether_addr_octet, &result, ETH_ALEN); /* see eth_random_addr in the kernel */ mac->ether_addr_octet[0] &= 0xfe; /* clear multicast bit */ |