diff options
author | Thomas Haller <thaller@redhat.com> | 2018-11-01 14:43:11 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-11-12 19:08:35 +0100 |
commit | 6d13616b9e97743b45794deb892b28b4d6ab1835 (patch) | |
tree | fdd2ee10c0c096b80dfef769e1dd416976af1bda /src/libsystemd-network/test-dhcp-client.c | |
parent | 43fc095532899121030750204f47ab8566514d90 (diff) | |
download | systemd-6d13616b9e97743b45794deb892b28b4d6ab1835.tar.gz |
dhcp: support endianness independent dhcp_identifier_set_iaid()
The previous code did htole64() followed by unaligned_write_be32() (the
XOR and shift in between is endianness agnostic). That means, on every
architeture there is always exactly one byte swap and the iaid is
dependent on endianness.
Since dhcp_identifier_set_iaid() is part of the DUID generation
algorithm, this cannot be fixed without changing the client-id.
In particular, as the client-id already depends on the machine-id (and
is thus inherrently host-specific), it is better to stick to the current
behavior.
However, add a parameter to switch between old and new behaviour.
Since the new behavior is unused, the only real purpose of this
change is to self-document the oddity of the function.
Fixes: 933f9caeeb2b3c1b951d330e04beb04226e5a890
Diffstat (limited to 'src/libsystemd-network/test-dhcp-client.c')
-rw-r--r-- | src/libsystemd-network/test-dhcp-client.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c index e92d4afac0..fe6788d91b 100644 --- a/src/libsystemd-network/test-dhcp-client.c +++ b/src/libsystemd-network/test-dhcp-client.c @@ -156,7 +156,8 @@ static void test_checksum(void) { } static void test_dhcp_identifier_set_iaid(void) { - uint32_t iaid; + uint32_t iaid_legacy; + be32_t iaid; int ifindex; for (;;) { @@ -169,11 +170,18 @@ static void test_dhcp_identifier_set_iaid(void) { break; } - assert_se(dhcp_identifier_set_iaid(ifindex, mac_addr, sizeof(mac_addr), &iaid) >= 0); + assert_se(dhcp_identifier_set_iaid(ifindex, mac_addr, sizeof(mac_addr), true, &iaid_legacy) >= 0); + assert_se(dhcp_identifier_set_iaid(ifindex, mac_addr, sizeof(mac_addr), false, &iaid) >= 0); - /* we expect, that the MAC address was hashed. Note that the value is in native + /* we expect, that the MAC address was hashed. The legacy value is in native * endianness. */ - assert_se(iaid == 0x8dde4ba8u); + assert_se(iaid_legacy == 0x8dde4ba8u); + assert_se(iaid == htole32(0x8dde4ba8u)); +#if __BYTE_ORDER == __LITTLE_ENDIAN + assert_se(iaid == iaid_legacy); +#else + assert_se(iaid == __bswap_32(iaid_legacy)); +#endif } static int check_options(uint8_t code, uint8_t len, const void *option, void *userdata) { @@ -185,7 +193,7 @@ static int check_options(uint8_t code, uint8_t len, const void *option, void *us size_t duid_len; assert_se(dhcp_identifier_set_duid_en(&duid, &duid_len) >= 0); - assert_se(dhcp_identifier_set_iaid(42, mac_addr, ETH_ALEN, &iaid) >= 0); + assert_se(dhcp_identifier_set_iaid(42, mac_addr, ETH_ALEN, true, &iaid) >= 0); assert_se(len == sizeof(uint8_t) + sizeof(uint32_t) + duid_len); assert_se(len == 19); |