]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: add NAMING_DEVICETREE_PORT_ALIASES to check of_node of netdevs...
authorMatthias Schiffer <matthias.schiffer@ew.tq-group.com>
Wed, 7 Aug 2024 10:01:24 +0000 (12:01 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 15 Aug 2024 16:20:49 +0000 (18:20 +0200)
The net_id builtin only checked the of_node of a netdev's parent device,
not that of the netdev itself. While it is common that netdevs don't have
an OF node assigned themselves, as they are derived from some parent
device, this is not always the case. In particular when a single
controller provides multiple ports that can be referenced indiviually in
the Device Tree (both for aliases/MAC address assignment and phandle
references), the correct of_node will be that of the netdev itself, not
that of the parent, so it needs to be checked, too.

A new naming scheme flag NAMING_DEVICETREE_PORT_ALIASES is added to
allow selecting the new behavior.

man/systemd.net-naming-scheme.xml
src/shared/netif-naming-scheme.h
src/udev/udev-builtin-net_id.c

index bb7899014505b1d64e42d7853adfdd0c6c176b4a..f825a841a1952d5c6189f69709bcd35ce41930e9 100644 (file)
 
           <listitem><para>PCI slot number is now read from <constant>firmware_node/sun</constant> sysfs file.</para>
 
+          <para>The naming scheme based on devicetree aliases was extended to support aliases for individual
+          interfaces of controllers with multiple ports.</para>
+
           <xi:include href="version-info.xml" xpointer="v257"/>
           </listitem>
         </varlistentry>
index 45a53291855f67c324b0c4d6dd25804646d09498..3ab1d752c87820a5fe7ed1b866b6d68402801162 100644 (file)
@@ -40,10 +40,11 @@ typedef enum NamingSchemeFlags {
         NAMING_XEN_VIF                   = 1 << 13, /* Generate names for Xen netfront devices */
         NAMING_BRIDGE_MULTIFUNCTION_SLOT = 1 << 14, /* Use PCI hotplug slot information associated with bridge, but only if PCI device is multifunction.
                                                      * This is disabled since v255, as it seems not to work at least for some setups. See issue #28929. */
-        NAMING_DEVICETREE_ALIASES        = 1 << 15, /* Generate names from devicetree aliases */
+        NAMING_DEVICETREE_ALIASES        = 1 << 15, /* Generate names from devicetree aliases of a netdev's parent's OF node */
         NAMING_USB_HOST                  = 1 << 16, /* Generate names for usb host */
         NAMING_SR_IOV_R                  = 1 << 17, /* Use "r" suffix for SR-IOV VF representors */
         NAMING_FIRMWARE_NODE_SUN         = 1 << 18, /* Use firmware_node/sun to get PCI slot number */
+        NAMING_DEVICETREE_PORT_ALIASES   = 1 << 19, /* Include aliases of OF nodes of a netdev itself, not just its parent. See PR #33958. */
 
         /* And now the masks that combine the features above */
         NAMING_V238 = 0,
@@ -63,7 +64,7 @@ typedef enum NamingSchemeFlags {
                                                        * patch later. NAMING_SR_IOV_R is enabled by default in
                                                        * systemd version 255, naming scheme "v255". */
         NAMING_V255 = NAMING_V254 & ~NAMING_BRIDGE_MULTIFUNCTION_SLOT,
-        NAMING_V257 = NAMING_V255 | NAMING_FIRMWARE_NODE_SUN,
+        NAMING_V257 = NAMING_V255 | NAMING_FIRMWARE_NODE_SUN | NAMING_DEVICETREE_PORT_ALIASES,
 
         EXTRA_NET_NAMING_SCHEMES
 
index d34357fdb214b903acf93f9a202b0d9414a38606..5094b953734cb812d5d4961e89926e0c1f305381 100644 (file)
@@ -822,7 +822,6 @@ static int names_platform(sd_device *dev, const char *prefix, EventMode mode) {
 static int names_devicetree(sd_device *dev, const char *prefix, EventMode mode) {
         _cleanup_(sd_device_unrefp) sd_device *aliases_dev = NULL, *ofnode_dev = NULL, *devicetree_dev = NULL;
         const char *ofnode_path, *ofnode_syspath, *devicetree_syspath;
-        sd_device *parent;
         int r;
 
         assert(dev);
@@ -835,14 +834,24 @@ static int names_devicetree(sd_device *dev, const char *prefix, EventMode mode)
         if (!streq(prefix, "en"))
                 return -EOPNOTSUPP;
 
-        /* check if our direct parent has an of_node */
-        r = sd_device_get_parent(dev, &parent);
-        if (r < 0)
-                return log_device_debug_errno(dev, r, "Failed to get parent device: %m");
+        /* check if the device itself has an of_node */
+        if (naming_scheme_has(NAMING_DEVICETREE_PORT_ALIASES)) {
+                r = sd_device_new_child(&ofnode_dev, dev, "of_node");
+                if (r < 0)
+                        log_device_debug_errno(dev, r, "Failed to get device of_node, ignoring: %m");
+        }
+        if (!ofnode_dev) {
+                sd_device *parent;
 
-        r = sd_device_new_child(&ofnode_dev, parent, "of_node");
-        if (r < 0)
-                return log_device_debug_errno(parent, r, "Failed to get 'of_node' child device: %m");
+                /* check if our direct parent has an of_node as a fallback */
+                r = sd_device_get_parent(dev, &parent);
+                if (r < 0)
+                        return log_device_debug_errno(dev, r, "Failed to get parent device: %m");
+
+                r = sd_device_new_child(&ofnode_dev, parent, "of_node");
+                if (r < 0)
+                        return log_device_debug_errno(parent, r, "Failed to get device of_node: %m");
+        }
 
         r = sd_device_get_syspath(ofnode_dev, &ofnode_syspath);
         if (r < 0)