From ba132ab58eacf43144b85522a50ffa75d18fd7c0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 19 Dec 2018 13:34:41 +0100 Subject: [PATCH] dhcp: fix generating MAC based client-id for infiniband For infiniband, only the last 8 bytes for the 20 bytes hardware address are relevant. At least, with respect to the settings - ipv4.dhcp-client-id=mac - ipv4.dhcp-client-id=perm-mac - ipv6.dhcp-duid=ll - ipv6.dhcp-duid=llt - ipv6.dhcp-duid=stable-ll - ipv6.dhcp-duid=stable-llt This is also what ISC dhclient on Fedora/RHEL does ([1], [2]). [1] https://bugzilla.redhat.com/show_bug.cgi?id=660681 [2] https://src.fedoraproject.org/rpms/dhcp/blob/3ccf3c8d815df4b8e11e1a04850975f099273d5d/f/dhcp-lpf-ib.patch https://bugzilla.redhat.com/show_bug.cgi?id=1658057 (cherry picked from commit 4523a376cc4910750e82a783ea98f104ce2e5118) --- src/devices/nm-device.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 42457f7135..977815bc96 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7474,6 +7474,22 @@ _ASSERT_arp_type (guint16 arp_type, nm_assert (hwaddr); } +static void +_hwaddr_get_relevant_part (guint16 arp_type, + const guint8 **hwaddr, + gsize *hwaddr_len) +{ + nm_assert (hwaddr); + nm_assert (hwaddr_len); + _ASSERT_arp_type (arp_type, *hwaddr, *hwaddr_len); + + /* for infiniband, we only consider the last 8 bytes. */ + if (arp_type == ARPHRD_INFINIBAND) { + *hwaddr += (INFINIBAND_ALEN - 8); + *hwaddr_len = 8; + } +} + static GBytes * dhcp4_get_client_id_mac (guint16 arp_type, const guint8 *hwaddr, @@ -7482,7 +7498,7 @@ dhcp4_get_client_id_mac (guint16 arp_type, guint8 *client_id_buf; const guint8 hwaddr_type = arp_type; - _ASSERT_arp_type (arp_type, hwaddr, hwaddr_len); + _hwaddr_get_relevant_part (arp_type, &hwaddr, &hwaddr_len); client_id_buf = g_malloc (hwaddr_len + 1); client_id_buf[0] = hwaddr_type; @@ -8233,7 +8249,7 @@ generate_duid_llt (guint16 arp_type, const guint16 hw_type = htons (arp_type); const guint32 duid_time = htonl (NM_MAX (0, time - EPOCH_DATETIME_200001010000)); - _ASSERT_arp_type (arp_type, hwaddr, hwaddr_len); + _hwaddr_get_relevant_part (arp_type, &hwaddr, &hwaddr_len); arr = g_new (guint8, 2 + 2 + 4 + hwaddr_len); @@ -8254,7 +8270,7 @@ generate_duid_ll (guint16 arp_type, const guint16 duid_type = htons (3); const guint16 hw_type = htons (arp_type); - _ASSERT_arp_type (arp_type, hwaddr, hwaddr_len); + _hwaddr_get_relevant_part (arp_type, &hwaddr, &hwaddr_len); arr = g_new (guint8, 2 + 2 + hwaddr_len);