]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: support getting usb path off the host
authorCharles Hardin <charles.hardin@chargepoint.com>
Mon, 10 Oct 2022 20:30:10 +0000 (13:30 -0700)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 31 Oct 2022 20:11:24 +0000 (21:11 +0100)
To support predictable interface names in various embeeded systems
add support for an additional naming scheming using the USB host
interface. Several asics have usb controllers that are platform
devices and not children of a pci interface. These embedded systems
should be able to enumerate interfaces by udev path as well to support
configurations and policies.

Signed-off-by: Charles Hardin <charles.hardin@chargepoint.com>
man/systemd.net-naming-scheme.xml
src/shared/netif-naming-scheme.c
src/shared/netif-naming-scheme.h
src/udev/udev-builtin-net_id.c

index 8aac42b49de13a1abf4421cfc5c2d7bbd675b349..1e2295ba7a842af4a756da9e82ddf4890bdd8c15 100644 (file)
           <term><varname>ID_NET_NAME_PATH=<replaceable>prefix</replaceable><constant>c</constant><replaceable>bus_id</replaceable></varname></term>
           <term><varname>ID_NET_NAME_PATH=<replaceable>prefix</replaceable><constant>a</constant><replaceable>vendor</replaceable><replaceable>model</replaceable><constant>i</constant><replaceable>instance</replaceable></varname></term>
           <term><varname>ID_NET_NAME_PATH=<replaceable>prefix</replaceable><constant>i</constant><replaceable>address</replaceable><constant>n</constant><replaceable>port_name</replaceable></varname></term>
+          <term><varname>ID_NET_NAME_PATH=<replaceable>prefix</replaceable><constant>u</constant><replaceable>port</replaceable>…</varname></term>
           <term><varname>ID_NET_NAME_PATH=<replaceable>prefix</replaceable>[<constant>P</constant><replaceable>domain</replaceable>]<constant>p</constant><replaceable>bus</replaceable><constant>s</constant><replaceable>slot</replaceable>[<constant>f</constant><replaceable>function</replaceable>][<constant>n</constant><replaceable>phys_port_name</replaceable>|<constant>d</constant><replaceable>dev_port</replaceable>]</varname></term>
           <term><varname>ID_NET_NAME_PATH=<replaceable>prefix</replaceable>[<constant>P</constant><replaceable>domain</replaceable>]<constant>p</constant><replaceable>bus</replaceable><constant>s</constant><replaceable>slot</replaceable>[<constant>f</constant><replaceable>function</replaceable>][<constant>n</constant><replaceable>phys_port_name</replaceable>|<constant>d</constant><replaceable>dev_port</replaceable>]<constant>b</constant><replaceable>number</replaceable></varname></term>
           <term><varname>ID_NET_NAME_PATH=<replaceable>prefix</replaceable>[<constant>P</constant><replaceable>domain</replaceable>]<constant>p</constant><replaceable>bus</replaceable><constant>s</constant><replaceable>slot</replaceable>[<constant>f</constant><replaceable>function</replaceable>][<constant>n</constant><replaceable>phys_port_name</replaceable>|<constant>d</constant><replaceable>dev_port</replaceable>]<constant>u</constant><replaceable>port</replaceable>…[<constant>c</constant><replaceable>config</replaceable>][<constant>i</constant><replaceable>interface</replaceable>]</varname></term>
           </listitem>
         </varlistentry>
 
+        <varlistentry>
+          <term><constant>v253</constant></term>
+
+          <listitem><para>Set <varname>ID_NET_NAME_PATH</varname> for usb devices not connected via a PCI bus.</para>
+          </listitem>
+        </varlistentry>
+
       </variablelist>
 
     <para>Note that <constant>latest</constant> may be used to denote the latest scheme known (to this
index 18748e537627376c612e303cb8b24cd47bb8979c..b6a97527d8cba160a696b727c852ea95534010bf 100644 (file)
@@ -25,6 +25,7 @@ static const NamingScheme naming_schemes[] = {
         { "v250", NAMING_V250 },
         { "v251", NAMING_V251 },
         { "v252", NAMING_V252 },
+        { "v253", NAMING_V253 },
         /* … add more schemes here, as the logic to name devices is updated … */
 
         EXTRA_NET_NAMING_MAP
index 4fa917096907c305e1aa77f17dc6af4ddc747d47..bb893870e91c48df10fc5e7ceda4751563795a5c 100644 (file)
@@ -38,6 +38,7 @@ 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 */
         NAMING_DEVICETREE_ALIASES        = 1 << 15, /* Generate names from devicetree aliases */
+        NAMING_USB_HOST                  = 1 << 16, /* Generate names for usb host */
 
         /* And now the masks that combine the features above */
         NAMING_V238 = 0,
@@ -51,6 +52,7 @@ typedef enum NamingSchemeFlags {
         NAMING_V250 = NAMING_V249 | NAMING_XEN_VIF,
         NAMING_V251 = NAMING_V250 | NAMING_BRIDGE_MULTIFUNCTION_SLOT,
         NAMING_V252 = NAMING_V251 | NAMING_DEVICETREE_ALIASES,
+        NAMING_V253 = NAMING_V252 | NAMING_USB_HOST,
 
         EXTRA_NET_NAMING_SCHEMES
 
index 75041237003297fe6bf6f2c8760769c95708efbc..557e4591912fb3be1f06208b7b06e8135b2a6b60 100644 (file)
@@ -1202,9 +1202,24 @@ static int builtin_net_id(sd_device *dev, sd_netlink **rtnl, int argc, char *arg
                 return 0;
         }
 
-        /* get PCI based path names, we compose only PCI based paths */
-        if (names_pci(dev, &info, &names) < 0)
+        /* get PCI based path names */
+        r = names_pci(dev, &info, &names);
+        if (r < 0) {
+                /*
+                 * check for usb devices that are not off pci interfaces to
+                 * support various on-chip asics that have usb ports
+                 */
+                if (r == -ENOENT &&
+                    naming_scheme_has(NAMING_USB_HOST) &&
+                    names_usb(dev, &names) >= 0 && names.type == NET_USB) {
+                        char str[ALTIFNAMSIZ];
+
+                        if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.usb_ports))
+                                udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+                }
+
                 return 0;
+        }
 
         /* plain PCI device */
         if (names.type == NET_PCI) {