udev: Disable HW-address-based naming for IB NICs
authorArseny Maslennikov <arseny@altlinux.org>
Wed, 29 Aug 2018 01:20:43 +0000 (04:20 +0300)
committerArseny Maslennikov <arseny@altlinux.org>
Tue, 18 Sep 2018 17:13:42 +0000 (20:13 +0300)
An InfiniBand network address is 20 bytes long. Only the least
significant 8 bytes can be interpreted as a persistent hardware unit
identifier; the other 12 are transiently derived at runtime from metadata
specific to the protocol stack.

However, since the network interface name length is hard-capped by
IFNAMSIZ at 16 chars and the 2-byte type prefix with '\0' at the end
leave us only at 13, we cannot squeeze a descriptive representation of a
HW address into an interface name. Thus, it makes the most sense to drop
the scheme for IPoIB interfaces entirely.

Currently udev just gets confused and does what it has been taught
to do: fetches the first six bytes and puts them into a permanent
device attribute.

src/udev/udev-builtin-net_id.c

index 239a825..d808ddc 100644 (file)
@@ -658,6 +658,23 @@ static int names_mac(struct udev_device *dev, struct netnames *names) {
         unsigned int i;
         unsigned int a1, a2, a3, a4, a5, a6;
 
+        /* Some kinds of devices tend to have hardware addresses
+         * that are impossible to use in an iface name.
+         */
+        s = udev_device_get_sysattr_value(dev, "type");
+        if (!s)
+                return EXIT_FAILURE;
+        i = strtoul(s, NULL, 0);
+        switch (i) {
+        /* The persistent part of a hardware address of an InfiniBand NIC
+         * is 8 bytes long. We cannot fit this much in an iface name.
+         */
+        case ARPHRD_INFINIBAND:
+                return -EINVAL;
+        default:
+                break;
+        }
+
         /* check for NET_ADDR_PERM, skip random MAC addresses */
         s = udev_device_get_sysattr_value(dev, "addr_assign_type");
         if (!s)