1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 * Predictable network interface device names based on:
5 * - firmware/bios-provided index numbers for on-board devices
6 * - firmware-provided pci-express hotplug slot index number
7 * - physical/geographical location of the hardware
8 * - the interface's MAC address
10 * http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames
12 * When the code here is changed, man/systemd.net-naming-scheme.xml must be updated too.
18 #include <net/if_arp.h>
22 #include <linux/pci_regs.h>
24 #include "alloc-util.h"
25 #include "dirent-util.h"
29 #include "naming-scheme.h"
30 #include "parse-util.h"
31 #include "proc-cmdline.h"
32 #include "stdio-util.h"
33 #include "string-util.h"
36 #include "udev-builtin.h"
38 #define ONBOARD_INDEX_MAX (16*1024-1)
53 enum netname_type type
;
59 char pci_slot
[IFNAMSIZ
];
60 char pci_path
[IFNAMSIZ
];
61 char pci_onboard
[IFNAMSIZ
];
62 const char *pci_onboard_label
;
64 char usb_ports
[IFNAMSIZ
];
65 char bcma_core
[IFNAMSIZ
];
66 char ccw_busid
[IFNAMSIZ
];
67 char vio_slot
[IFNAMSIZ
];
68 char platform_path
[IFNAMSIZ
];
69 char netdevsim_path
[IFNAMSIZ
];
73 sd_device
*physfn_pcidev
;
74 char suffix
[IFNAMSIZ
];
77 /* skip intermediate virtio devices */
78 static sd_device
*skip_virtio(sd_device
*dev
) {
81 /* there can only ever be one virtio bus per parent device, so we can
82 * safely ignore any virtio buses. see
83 * http://lists.linuxfoundation.org/pipermail/virtualization/2015-August/030331.html */
84 for (parent
= dev
; parent
; ) {
85 const char *subsystem
;
87 if (sd_device_get_subsystem(parent
, &subsystem
) < 0)
90 if (!streq(subsystem
, "virtio"))
93 if (sd_device_get_parent(parent
, &parent
) < 0)
100 static int get_virtfn_info(sd_device
*dev
, struct netnames
*names
, struct virtfn_info
*ret
) {
101 _cleanup_(sd_device_unrefp
) sd_device
*physfn_pcidev
= NULL
;
102 const char *physfn_link_file
, *syspath
;
103 _cleanup_free_
char *physfn_pci_syspath
= NULL
;
104 _cleanup_free_
char *virtfn_pci_syspath
= NULL
;
106 _cleanup_closedir_
DIR *dir
= NULL
;
107 char suffix
[IFNAMSIZ
];
114 r
= sd_device_get_syspath(names
->pcidev
, &syspath
);
118 /* Check if this is a virtual function. */
119 physfn_link_file
= strjoina(syspath
, "/physfn");
120 r
= chase_symlinks(physfn_link_file
, NULL
, 0, &physfn_pci_syspath
, NULL
);
124 /* Get physical function's pci device. */
125 r
= sd_device_new_from_syspath(&physfn_pcidev
, physfn_pci_syspath
);
129 /* Find the virtual function number by finding the right virtfn link. */
130 dir
= opendir(physfn_pci_syspath
);
134 FOREACH_DIRENT_ALL(dent
, dir
, break) {
135 _cleanup_free_
char *virtfn_link_file
= NULL
;
137 if (!startswith(dent
->d_name
, "virtfn"))
140 virtfn_link_file
= path_join(physfn_pci_syspath
, dent
->d_name
);
141 if (!virtfn_link_file
)
144 if (chase_symlinks(virtfn_link_file
, NULL
, 0, &virtfn_pci_syspath
, NULL
) < 0)
147 if (streq(syspath
, virtfn_pci_syspath
)) {
148 if (!snprintf_ok(suffix
, sizeof(suffix
), "v%s", &dent
->d_name
[6]))
157 ret
->physfn_pcidev
= TAKE_PTR(physfn_pcidev
);
158 strncpy(ret
->suffix
, suffix
, sizeof(ret
->suffix
));
163 /* retrieve on-board index number and label from firmware */
164 static int dev_pci_onboard(sd_device
*dev
, struct netnames
*names
) {
165 unsigned long idx
, dev_port
= 0;
166 const char *attr
, *port_name
= NULL
;
171 /* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
172 if (sd_device_get_sysattr_value(names
->pcidev
, "acpi_index", &attr
) < 0) {
173 /* SMBIOS type 41 — Onboard Devices Extended Information */
174 r
= sd_device_get_sysattr_value(names
->pcidev
, "index", &attr
);
179 r
= safe_atolu(attr
, &idx
);
182 if (idx
== 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX
))
185 /* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to
186 * report for example). Let's define a cut-off where we don't consider the index reliable anymore. We
187 * pick some arbitrary cut-off, which is somewhere beyond the realistic number of physical network
188 * interface a system might have. Ideally the kernel would already filter his crap for us, but it
189 * doesn't currently. */
190 if (idx
> ONBOARD_INDEX_MAX
)
193 /* kernel provided port index for multiple ports on a single PCI function */
194 if (sd_device_get_sysattr_value(dev
, "dev_port", &attr
) >= 0)
195 dev_port
= strtoul(attr
, NULL
, 10);
197 /* kernel provided front panel port name for multiple port PCI device */
198 (void) sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
200 s
= names
->pci_onboard
;
201 l
= sizeof(names
->pci_onboard
);
202 l
= strpcpyf(&s
, l
, "o%lu", idx
);
204 l
= strpcpyf(&s
, l
, "n%s", port_name
);
205 else if (dev_port
> 0)
206 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
208 names
->pci_onboard
[0] = '\0';
210 if (sd_device_get_sysattr_value(names
->pcidev
, "label", &names
->pci_onboard_label
) < 0)
211 names
->pci_onboard_label
= NULL
;
216 /* read the 256 bytes PCI configuration space to check the multi-function bit */
217 static bool is_pci_multifunction(sd_device
*dev
) {
218 _cleanup_close_
int fd
= -1;
219 const char *filename
, *syspath
;
222 if (sd_device_get_syspath(dev
, &syspath
) < 0)
225 filename
= strjoina(syspath
, "/config");
226 fd
= open(filename
, O_RDONLY
| O_CLOEXEC
);
229 if (read(fd
, &config
, sizeof(config
)) != sizeof(config
))
232 /* bit 0-6 header type, bit 7 multi/single function device */
233 return config
[PCI_HEADER_TYPE
] & 0x80;
236 static bool is_pci_ari_enabled(sd_device
*dev
) {
239 if (sd_device_get_sysattr_value(dev
, "ari_enabled", &a
) < 0)
242 return streq(a
, "1");
245 static int dev_pci_slot(sd_device
*dev
, struct netnames
*names
) {
246 unsigned long dev_port
= 0;
247 unsigned domain
, bus
, slot
, func
, hotplug_slot
= 0;
250 const char *sysname
, *attr
, *port_name
= NULL
, *syspath
;
251 _cleanup_(sd_device_unrefp
) sd_device
*pci
= NULL
;
252 sd_device
*hotplug_slot_dev
;
253 char slots
[PATH_MAX
];
254 _cleanup_closedir_
DIR *dir
= NULL
;
258 r
= sd_device_get_sysname(names
->pcidev
, &sysname
);
262 if (sscanf(sysname
, "%x:%x:%x.%u", &domain
, &bus
, &slot
, &func
) != 4)
265 if (naming_scheme_has(NAMING_NPAR_ARI
) &&
266 is_pci_ari_enabled(names
->pcidev
))
267 /* ARI devices support up to 256 functions on a single device ("slot"), and interpret the
268 * traditional 5-bit slot and 3-bit function number as a single 8-bit function number,
269 * where the slot makes up the upper 5 bits. */
272 /* kernel provided port index for multiple ports on a single PCI function */
273 if (sd_device_get_sysattr_value(dev
, "dev_port", &attr
) >= 0) {
274 dev_port
= strtoul(attr
, NULL
, 10);
275 /* With older kernels IP-over-InfiniBand network interfaces sometimes erroneously
276 * provide the port number in the 'dev_id' sysfs attribute instead of 'dev_port',
277 * which thus stays initialized as 0. */
279 sd_device_get_sysattr_value(dev
, "type", &attr
) >= 0) {
282 type
= strtoul(attr
, NULL
, 10);
283 if (type
== ARPHRD_INFINIBAND
&&
284 sd_device_get_sysattr_value(dev
, "dev_id", &attr
) >= 0)
285 dev_port
= strtoul(attr
, NULL
, 16);
289 /* kernel provided front panel port name for multi-port PCI device */
290 (void) sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
292 /* compose a name based on the raw kernel's PCI bus, slot numbers */
294 l
= sizeof(names
->pci_path
);
296 l
= strpcpyf(&s
, l
, "P%u", domain
);
297 l
= strpcpyf(&s
, l
, "p%us%u", bus
, slot
);
298 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
299 l
= strpcpyf(&s
, l
, "f%u", func
);
301 l
= strpcpyf(&s
, l
, "n%s", port_name
);
302 else if (dev_port
> 0)
303 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
305 names
->pci_path
[0] = '\0';
307 /* ACPI _SUN — slot user number */
308 r
= sd_device_new_from_subsystem_sysname(&pci
, "subsystem", "pci");
312 r
= sd_device_get_syspath(pci
, &syspath
);
315 if (!snprintf_ok(slots
, sizeof slots
, "%s/slots", syspath
))
316 return -ENAMETOOLONG
;
318 dir
= opendir(slots
);
322 hotplug_slot_dev
= names
->pcidev
;
323 while (hotplug_slot_dev
) {
324 if (sd_device_get_sysname(hotplug_slot_dev
, &sysname
) < 0)
327 FOREACH_DIRENT_ALL(dent
, dir
, break) {
330 _cleanup_free_
char *address
= NULL
;
332 if (dent
->d_name
[0] == '.')
334 r
= safe_atou_full(dent
->d_name
, 10, &i
);
338 /* match slot address with device by stripping the function */
339 if (snprintf_ok(str
, sizeof str
, "%s/%s/address", slots
, dent
->d_name
) &&
340 read_one_line_file(str
, &address
) >= 0 &&
341 startswith(sysname
, address
)) {
346 if (hotplug_slot
> 0)
348 if (sd_device_get_parent_with_subsystem_devtype(hotplug_slot_dev
, "pci", NULL
, &hotplug_slot_dev
) < 0)
353 if (hotplug_slot
> 0) {
355 l
= sizeof(names
->pci_slot
);
357 l
= strpcpyf(&s
, l
, "P%d", domain
);
358 l
= strpcpyf(&s
, l
, "s%d", hotplug_slot
);
359 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
360 l
= strpcpyf(&s
, l
, "f%d", func
);
362 l
= strpcpyf(&s
, l
, "n%s", port_name
);
363 else if (dev_port
> 0)
364 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
366 names
->pci_slot
[0] = '\0';
372 static int names_vio(sd_device
*dev
, struct netnames
*names
) {
374 unsigned busid
, slotid
, ethid
;
375 const char *syspath
, *subsystem
;
378 /* check if our direct parent is a VIO device with no other bus in-between */
379 r
= sd_device_get_parent(dev
, &parent
);
383 r
= sd_device_get_subsystem(parent
, &subsystem
);
386 if (!streq("vio", subsystem
))
389 /* The devices' $DEVPATH number is tied to (virtual) hardware (slot id
390 * selected in the HMC), thus this provides a reliable naming (e.g.
391 * "/devices/vio/30000002/net/eth1"); we ignore the bus number, as
392 * there should only ever be one bus, and then remove leading zeros. */
393 r
= sd_device_get_syspath(dev
, &syspath
);
397 if (sscanf(syspath
, "/sys/devices/vio/%4x%4x/net/eth%u", &busid
, &slotid
, ðid
) != 3)
400 xsprintf(names
->vio_slot
, "v%u", slotid
);
401 names
->type
= NET_VIO
;
405 #define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
406 #define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
407 #define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
409 static int names_platform(sd_device
*dev
, struct netnames
*names
, bool test
) {
412 unsigned model
, instance
, ethid
;
413 const char *syspath
, *pattern
, *validchars
, *subsystem
;
416 /* check if our direct parent is a platform device with no other bus in-between */
417 r
= sd_device_get_parent(dev
, &parent
);
421 r
= sd_device_get_subsystem(parent
, &subsystem
);
425 if (!streq("platform", subsystem
))
428 r
= sd_device_get_syspath(dev
, &syspath
);
432 /* syspath is too short, to have a valid ACPI instance */
433 if (strlen(syspath
) < sizeof _PLATFORM_TEST
)
436 /* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
437 if (syspath
[sizeof _PLATFORM_TEST
- 1] == ':') {
438 pattern
= _PLATFORM_PATTERN4
;
439 validchars
= UPPERCASE_LETTERS DIGITS
;
441 pattern
= _PLATFORM_PATTERN3
;
442 validchars
= UPPERCASE_LETTERS
;
445 /* Platform devices are named after ACPI table match, and instance id
446 * eg. "/sys/devices/platform/HISI00C2:00");
447 * The Vendor (3 or 4 char), followed by hexdecimal model number : instance id.
450 #pragma GCC diagnostic push
451 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
452 if (sscanf(syspath
, pattern
, vendor
, &model
, &instance
, ðid
) != 4)
454 #pragma GCC diagnostic pop
456 if (!in_charset(vendor
, validchars
))
459 ascii_strlower(vendor
);
461 xsprintf(names
->platform_path
, "a%s%xi%u", vendor
, model
, instance
);
462 names
->type
= NET_PLATFORM
;
466 static int names_pci(sd_device
*dev
, struct netnames
*names
) {
468 struct netnames vf_names
= {};
469 struct virtfn_info vf_info
= {};
470 const char *subsystem
;
476 r
= sd_device_get_parent(dev
, &parent
);
479 /* skip virtio subsystem if present */
480 parent
= skip_virtio(parent
);
485 /* check if our direct parent is a PCI device with no other bus in-between */
486 if (sd_device_get_subsystem(parent
, &subsystem
) >= 0 &&
487 streq("pci", subsystem
)) {
488 names
->type
= NET_PCI
;
489 names
->pcidev
= parent
;
491 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "pci", NULL
, &names
->pcidev
);
496 if (naming_scheme_has(NAMING_SR_IOV_V
) &&
497 get_virtfn_info(dev
, names
, &vf_info
) >= 0) {
498 /* If this is an SR-IOV virtual device, get base name using physical device and add virtfn suffix. */
499 vf_names
.pcidev
= vf_info
.physfn_pcidev
;
500 dev_pci_onboard(dev
, &vf_names
);
501 dev_pci_slot(dev
, &vf_names
);
502 if (vf_names
.pci_onboard
[0])
503 if (strlen(vf_names
.pci_onboard
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_onboard
))
504 strscpyl(names
->pci_onboard
, sizeof(names
->pci_onboard
),
505 vf_names
.pci_onboard
, vf_info
.suffix
, NULL
);
506 if (vf_names
.pci_slot
[0])
507 if (strlen(vf_names
.pci_slot
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_slot
))
508 strscpyl(names
->pci_slot
, sizeof(names
->pci_slot
),
509 vf_names
.pci_slot
, vf_info
.suffix
, NULL
);
510 if (vf_names
.pci_path
[0])
511 if (strlen(vf_names
.pci_path
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_path
))
512 strscpyl(names
->pci_path
, sizeof(names
->pci_path
),
513 vf_names
.pci_path
, vf_info
.suffix
, NULL
);
514 sd_device_unref(vf_info
.physfn_pcidev
);
516 dev_pci_onboard(dev
, names
);
517 dev_pci_slot(dev
, names
);
523 static int names_usb(sd_device
*dev
, struct netnames
*names
) {
525 char name
[256], *ports
, *config
, *interf
, *s
;
533 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "usb", "usb_interface", &usbdev
);
537 r
= sd_device_get_sysname(usbdev
, &sysname
);
541 /* get USB port number chain, configuration, interface */
542 strscpy(name
, sizeof(name
), sysname
);
543 s
= strchr(name
, '-');
548 s
= strchr(ports
, ':');
554 s
= strchr(config
, '.');
560 /* prefix every port number in the chain with "u" */
562 while ((s
= strchr(s
, '.')))
564 s
= names
->usb_ports
;
565 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "u", ports
, NULL
);
567 /* append USB config number, suppress the common config == 1 */
568 if (!streq(config
, "1"))
569 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "c", config
, NULL
);
571 /* append USB interface number, suppress the interface == 0 */
572 if (!streq(interf
, "0"))
573 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "i", interf
, NULL
);
575 return -ENAMETOOLONG
;
577 names
->type
= NET_USB
;
581 static int names_bcma(sd_device
*dev
, struct netnames
*names
) {
590 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "bcma", NULL
, &bcmadev
);
594 r
= sd_device_get_sysname(bcmadev
, &sysname
);
598 /* bus num:core num */
599 if (sscanf(sysname
, "bcma%*u:%u", &core
) != 1)
601 /* suppress the common core == 0 */
603 xsprintf(names
->bcma_core
, "b%u", core
);
605 names
->type
= NET_BCMA
;
609 static int names_ccw(sd_device
*dev
, struct netnames
*names
) {
611 const char *bus_id
, *subsys
;
619 /* Retrieve the associated CCW device */
620 r
= sd_device_get_parent(dev
, &cdev
);
624 /* skip virtio subsystem if present */
625 cdev
= skip_virtio(cdev
);
629 r
= sd_device_get_subsystem(cdev
, &subsys
);
633 /* Network devices are either single or grouped CCW devices */
634 if (!STR_IN_SET(subsys
, "ccwgroup", "ccw"))
637 /* Retrieve bus-ID of the CCW device. The bus-ID uniquely
638 * identifies the network device on the Linux on System z channel
639 * subsystem. Note that the bus-ID contains lowercase characters.
641 r
= sd_device_get_sysname(cdev
, &bus_id
);
645 /* Check the length of the bus-ID. Rely on the fact that the kernel provides a correct bus-ID;
646 * alternatively, improve this check and parse and verify each bus-ID part...
648 bus_id_len
= strlen(bus_id
);
649 if (!IN_SET(bus_id_len
, 8, 9))
652 /* Strip leading zeros from the bus id for aesthetic purposes. This
653 * keeps the ccw names stable, yet much shorter in general case of
654 * bus_id 0.0.0600 -> 600. This is similar to e.g. how PCI domain is
655 * not prepended when it is zero. Preserve the last 0 for 0.0.0000.
657 bus_id_start
= strspn(bus_id
, ".0");
658 bus_id
+= bus_id_start
< bus_id_len
? bus_id_start
: bus_id_len
- 1;
660 /* Store the CCW bus-ID for use as network device name */
661 if (snprintf_ok(names
->ccw_busid
, sizeof(names
->ccw_busid
), "c%s", bus_id
))
662 names
->type
= NET_CCW
;
667 static int names_mac(sd_device
*dev
, struct netnames
*names
) {
670 unsigned a1
, a2
, a3
, a4
, a5
, a6
;
673 /* Some kinds of devices tend to have hardware addresses
674 * that are impossible to use in an iface name.
676 r
= sd_device_get_sysattr_value(dev
, "type", &s
);
680 i
= strtoul(s
, NULL
, 0);
682 /* The persistent part of a hardware address of an InfiniBand NIC
683 * is 8 bytes long. We cannot fit this much in an iface name.
685 case ARPHRD_INFINIBAND
:
691 /* check for NET_ADDR_PERM, skip random MAC addresses */
692 r
= sd_device_get_sysattr_value(dev
, "addr_assign_type", &s
);
695 i
= strtoul(s
, NULL
, 0);
699 r
= sd_device_get_sysattr_value(dev
, "address", &s
);
702 if (sscanf(s
, "%x:%x:%x:%x:%x:%x", &a1
, &a2
, &a3
, &a4
, &a5
, &a6
) != 6)
705 /* skip empty MAC addresses */
706 if (a1
+ a2
+ a3
+ a4
+ a5
+ a6
== 0)
715 names
->mac_valid
= true;
719 static int names_netdevsim(sd_device
*dev
, struct netnames
*names
) {
720 sd_device
*netdevsimdev
;
723 const char *port_name
= NULL
;
727 if (!naming_scheme_has(NAMING_NETDEVSIM
))
733 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "netdevsim", NULL
, &netdevsimdev
);
736 r
= sd_device_get_sysname(netdevsimdev
, &sysname
);
740 if (sscanf(sysname
, "netdevsim%u", &addr
) != 1)
743 r
= sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
747 ok
= snprintf_ok(names
->netdevsim_path
, sizeof(names
->netdevsim_path
), "i%un%s", addr
, port_name
);
751 names
->type
= NET_NETDEVSIM
;
756 /* IEEE Organizationally Unique Identifier vendor string */
757 static int ieee_oui(sd_device
*dev
, struct netnames
*names
, bool test
) {
760 if (!names
->mac_valid
)
762 /* skip commonly misused 00:00:00 (Xerox) prefix */
763 if (memcmp(names
->mac
, "\0\0\0", 3) == 0)
765 xsprintf(str
, "OUI:%02X%02X%02X%02X%02X%02X", names
->mac
[0],
766 names
->mac
[1], names
->mac
[2], names
->mac
[3], names
->mac
[4],
768 udev_builtin_hwdb_lookup(dev
, NULL
, str
, NULL
, test
);
772 static int builtin_net_id(sd_device
*dev
, int argc
, char *argv
[], bool test
) {
773 const char *s
, *p
, *devtype
, *prefix
= "en";
774 struct netnames names
= {};
778 /* handle only ARPHRD_ETHER, ARPHRD_SLIP and ARPHRD_INFINIBAND devices */
779 r
= sd_device_get_sysattr_value(dev
, "type", &s
);
783 i
= strtoul(s
, NULL
, 0);
788 case ARPHRD_INFINIBAND
:
789 if (naming_scheme_has(NAMING_INFINIBAND
))
801 /* skip stacked devices, like VLANs, ... */
802 r
= sd_device_get_sysattr_value(dev
, "ifindex", &s
);
805 r
= sd_device_get_sysattr_value(dev
, "iflink", &p
);
811 if (sd_device_get_devtype(dev
, &devtype
) >= 0) {
812 if (streq("wlan", devtype
))
814 else if (streq("wwan", devtype
))
818 udev_builtin_add_property(dev
, test
, "ID_NET_NAMING_SCHEME", naming_scheme()->name
);
820 r
= names_mac(dev
, &names
);
821 if (r
>= 0 && names
.mac_valid
) {
824 xsprintf(str
, "%sx%02x%02x%02x%02x%02x%02x", prefix
,
825 names
.mac
[0], names
.mac
[1], names
.mac
[2],
826 names
.mac
[3], names
.mac
[4], names
.mac
[5]);
827 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_MAC", str
);
829 ieee_oui(dev
, &names
, test
);
832 /* get path names for Linux on System z network devices */
833 if (names_ccw(dev
, &names
) >= 0 && names
.type
== NET_CCW
) {
836 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.ccw_busid
))
837 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
841 /* get ibmveth/ibmvnic slot-based names. */
842 if (names_vio(dev
, &names
) >= 0 && names
.type
== NET_VIO
) {
845 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.vio_slot
))
846 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
850 /* get ACPI path names for ARM64 platform devices */
851 if (names_platform(dev
, &names
, test
) >= 0 && names
.type
== NET_PLATFORM
) {
854 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.platform_path
))
855 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
859 /* get netdevsim path names */
860 if (names_netdevsim(dev
, &names
) >= 0 && names
.type
== NET_NETDEVSIM
) {
863 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.netdevsim_path
))
864 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
869 /* get PCI based path names, we compose only PCI based paths */
870 if (names_pci(dev
, &names
) < 0)
873 /* plain PCI device */
874 if (names
.type
== NET_PCI
) {
877 if (names
.pci_onboard
[0] &&
878 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_onboard
))
879 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_ONBOARD", str
);
881 if (names
.pci_onboard_label
&&
882 snprintf_ok(str
, sizeof str
, "%s%s",
883 naming_scheme_has(NAMING_LABEL_NOPREFIX
) ? "" : prefix
,
884 names
.pci_onboard_label
))
885 udev_builtin_add_property(dev
, test
, "ID_NET_LABEL_ONBOARD", str
);
887 if (names
.pci_path
[0] &&
888 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_path
))
889 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
891 if (names
.pci_slot
[0] &&
892 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_slot
))
893 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
898 if (names_usb(dev
, &names
) >= 0 && names
.type
== NET_USB
) {
901 if (names
.pci_path
[0] &&
902 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.usb_ports
))
903 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
905 if (names
.pci_slot
[0] &&
906 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.usb_ports
))
907 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
912 if (names_bcma(dev
, &names
) >= 0 && names
.type
== NET_BCMA
) {
915 if (names
.pci_path
[0] &&
916 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.bcma_core
))
917 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
919 if (names
.pci_slot
[0] &&
920 snprintf(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.bcma_core
))
921 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
928 const UdevBuiltin udev_builtin_net_id
= {
930 .cmd
= builtin_net_id
,
931 .help
= "Network device properties",