]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd-network/dhcp-identifier.c
DHCP DUID, IAID configuration options
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-identifier.c
index f8e6cb6ea98ce72ac012423004db07af68789d04..4f7d4d8bf2ba6cc31143b9b7591dd80833f9466b 100644 (file)
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
 /***
   This file is part of systemd.
 
   along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
+#include "libudev.h"
 #include "sd-id128.h"
 
 #include "dhcp-identifier.h"
 #include "dhcp6-protocol.h"
-#include "libudev.h"
 #include "network-internal.h"
 #include "siphash24.h"
 #include "sparse-endian.h"
@@ -45,14 +43,14 @@ int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
         if (r < 0)
                 return r;
 
-        unaligned_write_be16(&duid->type, DHCP6_DUID_EN);
+        unaligned_write_be16(&duid->type, DUID_TYPE_EN);
         unaligned_write_be32(&duid->en.pen, SYSTEMD_PEN);
 
         *len = sizeof(duid->type) + sizeof(duid->en);
 
         /* a bit of snake-oil perhaps, but no need to expose the machine-id
            directly; duid->en.id might not be aligned, so we need to copy */
-        siphash24(&hash, &machine_id, sizeof(machine_id), HASH_KEY.bytes);
+        hash = htole64(siphash24(&machine_id, sizeof(machine_id), HASH_KEY.bytes));
         memcpy(duid->en.id, &hash, sizeof(duid->en.id));
 
         return 0;
@@ -86,10 +84,12 @@ int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_i
         }
 
         if (name)
-                siphash24(&id, name, strlen(name), HASH_KEY.bytes);
+                id = siphash24(name, strlen(name), HASH_KEY.bytes);
         else
                 /* fall back to MAC address if no predictable name available */
-                siphash24(&id, mac, mac_len, HASH_KEY.bytes);
+                id = siphash24(mac, mac_len, HASH_KEY.bytes);
+
+        id = htole64(id);
 
         /* fold into 32 bits */
         unaligned_write_be32(_id, (id & 0xffffffff) ^ (id >> 32));