From: Alex Fox <alex.fox@neonix.io>
Subject: [PATCH] Fix Infiniband device detection

Detecting an Infiniband interface by testing for the existence of
/sys/class/net/%link%/device/infiniband is unreliable, as an
Infiniband capable port running in Ethernet mode may still have
the Infiniband directory in sysfs. When this type of port is in
Ethernet mode, ifupdown attempts and fails to create an Infiniband
partition on the Ethernet port, instead of creating a VLAN.

This patch instead only creates Infiniband partitions when an
interface's type is ARPHRD_INFINIBAND (32).

--- a/link.defn
+++ b/link.defn
@@ -16,7 +16,7 @@
     if test -d /sys/class/net/%link% -a \
             ! -d /sys/class/net/%iface0% ; \
     then \
-        if test -d /sys/class/net/%link%/device/infiniband; then \
+        if test `cat /sys/class/net/%link%/type` -eq 32; then \
             echo 0x%vlan_id1% > /sys/class/net/%link%/create_child; \
         else \
             /bin/ip link set up dev %link%; \
@@ -27,7 +27,7 @@
 	if (iface_is_lo())
     [[/bin/ip link set %iface0% alias "%description%"]]
   down
-    if test -d /sys/class/net/%link%/device/infiniband; then \
+    if test `cat /sys/class/net/%link%/type` -eq 32; then \
         echo 0x%vlan_id1% > /sys/class/net/%link%/delete_child; \
     else \
         /bin/ip link del %iface%; \
--- a/tests/linux/up.7
+++ b/tests/linux/up.7
@@ -21,7 +21,7 @@
 /bin/ip -6 addr add 3ffe:ffff:100:f101::1/64  dev eth0  nodad
 
 /bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
-if test -d /sys/class/net/eth0 -a             ! -d /sys/class/net/eth0.1 ;     then         if test -d /sys/class/net/eth0/device/infiniband; then             echo 0x1 > /sys/class/net/eth0/create_child;         else             /bin/ip link set up dev eth0;             /bin/ip link add link eth0 name eth0.1 type vlan id 1; 	fi;     fi
+if test -d /sys/class/net/eth0 -a             ! -d /sys/class/net/eth0.1 ;     then         if test `cat /sys/class/net/eth0/type` -eq 32; then             echo 0x1 > /sys/class/net/eth0/create_child;         else             /bin/ip link set up dev eth0;             /bin/ip link add link eth0 name eth0.1 type vlan id 1; 	fi;     fi
 
 ifup: configuring interface eth0.1=eth0.1 (inet6)
 /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
@@ -34,7 +34,7 @@
 /bin/ip -6 addr add 3ffe:ffff:120:f101::1/64  dev eth0.1  nodad
 
 /bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
-if test -d /sys/class/net/eth0 -a             ! -d /sys/class/net/eth0.0201 ;     then         if test -d /sys/class/net/eth0/device/infiniband; then             echo 0x0201 > /sys/class/net/eth0/create_child;         else             /bin/ip link set up dev eth0;             /bin/ip link add link eth0 name eth0.0201 type vlan id 201; 	fi;     fi
+if test -d /sys/class/net/eth0 -a             ! -d /sys/class/net/eth0.0201 ;     then         if test `cat /sys/class/net/eth0/type` -eq 32; then             echo 0x0201 > /sys/class/net/eth0/create_child;         else             /bin/ip link set up dev eth0;             /bin/ip link add link eth0 name eth0.0201 type vlan id 201; 	fi;     fi
 
 ifup: configuring interface eth0.0201=eth0.0201 (inet)
 /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
@@ -42,7 +42,7 @@
 /bin/ip link set dev eth0.0201   up
 
 /bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
-if test -d /sys/class/net/br0 -a             ! -d /sys/class/net/br0.0201 ;     then         if test -d /sys/class/net/br0/device/infiniband; then             echo 0x0201 > /sys/class/net/br0/create_child;         else             /bin/ip link set up dev br0;             /bin/ip link add link br0 name br0.0201 type vlan id 201; 	fi;     fi
+if test -d /sys/class/net/br0 -a             ! -d /sys/class/net/br0.0201 ;     then         if test `cat /sys/class/net/br0/type` -eq 32; then             echo 0x0201 > /sys/class/net/br0/create_child;         else             /bin/ip link set up dev br0;             /bin/ip link add link br0 name br0.0201 type vlan id 201; 	fi;     fi
 
 ifup: configuring interface br0.0201=br0.0201 (inet)
 /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
@@ -50,7 +50,7 @@
 
 /bin/ip link set dev br0.0201 up 2>/dev/null || true
 /bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
-if test -d /sys/class/net/br0 -a             ! -d /sys/class/net/br0.0202 ;     then         if test -d /sys/class/net/br0/device/infiniband; then             echo 0x0202 > /sys/class/net/br0/create_child;         else             /bin/ip link set up dev br0;             /bin/ip link add link br0 name br0.0202 type vlan id 202; 	fi;     fi
+if test -d /sys/class/net/br0 -a             ! -d /sys/class/net/br0.0202 ;     then         if test `cat /sys/class/net/br0/type` -eq 32; then             echo 0x0202 > /sys/class/net/br0/create_child;         else             /bin/ip link set up dev br0;             /bin/ip link add link br0 name br0.0202 type vlan id 202; 	fi;     fi
 
 ifup: configuring interface br0.0202=br0.0202 (inet)
 /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
--- a/tests/linux/up.8
+++ b/tests/linux/up.8
@@ -20,7 +20,7 @@
 echo hihi
 echo hellolo
 /bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
-if test -d /sys/class/net/eth2 -a             ! -d /sys/class/net/eth2.2 ;     then         if test -d /sys/class/net/eth2/device/infiniband; then             echo 0x2 > /sys/class/net/eth2/create_child;         else             /bin/ip link set up dev eth2;             /bin/ip link add link eth2 name eth2.2 type vlan id 2; 	fi;     fi
+if test -d /sys/class/net/eth2 -a             ! -d /sys/class/net/eth2.2 ;     then         if test `cat /sys/class/net/eth2/type` -eq 32; then             echo 0x2 > /sys/class/net/eth2/create_child;         else             /bin/ip link set up dev eth2;             /bin/ip link add link eth2 name eth2.2 type vlan id 2; 	fi;     fi
 
 ifup: configuring interface eth2.2=eth2.2 (inet)
 /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
@@ -28,7 +28,7 @@
 /bin/ip link set dev eth2.2   up
 
 /bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
-if test -d /sys/class/net/eth2 -a             ! -d /sys/class/net/eth2.2 ;     then         if test -d /sys/class/net/eth2/device/infiniband; then             echo 0x2 > /sys/class/net/eth2/create_child;         else             /bin/ip link set up dev eth2;             /bin/ip link add link eth2 name eth2.2 type vlan id 2; 	fi;     fi
+if test -d /sys/class/net/eth2 -a             ! -d /sys/class/net/eth2.2 ;     then         if test `cat /sys/class/net/eth2/type` -eq 32; then             echo 0x2 > /sys/class/net/eth2/create_child;         else             /bin/ip link set up dev eth2;             /bin/ip link add link eth2 name eth2.2 type vlan id 2; 	fi;     fi
 
 ifup: configuring interface eth2.2:3=eth2.2:3 (inet)
 /bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
