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>
24 #include <linux/pci_regs.h>
26 #include "alloc-util.h"
27 #include "dirent-util.h"
31 #include "naming-scheme.h"
32 #include "parse-util.h"
33 #include "proc-cmdline.h"
34 #include "stdio-util.h"
35 #include "string-util.h"
38 #include "udev-builtin.h"
40 #define ONBOARD_INDEX_MAX (16*1024-1)
55 enum netname_type type
;
61 char pci_slot
[IFNAMSIZ
];
62 char pci_path
[IFNAMSIZ
];
63 char pci_onboard
[IFNAMSIZ
];
64 const char *pci_onboard_label
;
66 char usb_ports
[IFNAMSIZ
];
67 char bcma_core
[IFNAMSIZ
];
68 char ccw_busid
[IFNAMSIZ
];
69 char vio_slot
[IFNAMSIZ
];
70 char platform_path
[IFNAMSIZ
];
71 char netdevsim_path
[IFNAMSIZ
];
75 sd_device
*physfn_pcidev
;
76 char suffix
[IFNAMSIZ
];
79 /* skip intermediate virtio devices */
80 static sd_device
*skip_virtio(sd_device
*dev
) {
83 /* there can only ever be one virtio bus per parent device, so we can
84 * safely ignore any virtio buses. see
85 * http://lists.linuxfoundation.org/pipermail/virtualization/2015-August/030331.html */
86 for (parent
= dev
; parent
; ) {
87 const char *subsystem
;
89 if (sd_device_get_subsystem(parent
, &subsystem
) < 0)
92 if (!streq(subsystem
, "virtio"))
95 if (sd_device_get_parent(parent
, &parent
) < 0)
102 static int get_virtfn_info(sd_device
*dev
, struct netnames
*names
, struct virtfn_info
*ret
) {
103 _cleanup_(sd_device_unrefp
) sd_device
*physfn_pcidev
= NULL
;
104 const char *physfn_link_file
, *syspath
;
105 _cleanup_free_
char *physfn_pci_syspath
= NULL
;
106 _cleanup_free_
char *virtfn_pci_syspath
= NULL
;
108 _cleanup_closedir_
DIR *dir
= NULL
;
109 char suffix
[IFNAMSIZ
];
116 r
= sd_device_get_syspath(names
->pcidev
, &syspath
);
120 /* Check if this is a virtual function. */
121 physfn_link_file
= strjoina(syspath
, "/physfn");
122 r
= chase_symlinks(physfn_link_file
, NULL
, 0, &physfn_pci_syspath
);
126 /* Get physical function's pci device. */
127 r
= sd_device_new_from_syspath(&physfn_pcidev
, physfn_pci_syspath
);
131 /* Find the virtual function number by finding the right virtfn link. */
132 dir
= opendir(physfn_pci_syspath
);
136 FOREACH_DIRENT_ALL(dent
, dir
, break) {
137 _cleanup_free_
char *virtfn_link_file
= NULL
;
139 if (!startswith(dent
->d_name
, "virtfn"))
142 virtfn_link_file
= path_join(physfn_pci_syspath
, dent
->d_name
);
143 if (!virtfn_link_file
)
146 if (chase_symlinks(virtfn_link_file
, NULL
, 0, &virtfn_pci_syspath
) < 0)
149 if (streq(syspath
, virtfn_pci_syspath
)) {
150 if (!snprintf_ok(suffix
, sizeof(suffix
), "v%s", &dent
->d_name
[6]))
159 ret
->physfn_pcidev
= TAKE_PTR(physfn_pcidev
);
160 strncpy(ret
->suffix
, suffix
, sizeof(ret
->suffix
));
165 /* retrieve on-board index number and label from firmware */
166 static int dev_pci_onboard(sd_device
*dev
, struct netnames
*names
) {
167 unsigned long idx
, dev_port
= 0;
168 const char *attr
, *port_name
= NULL
;
173 /* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
174 if (sd_device_get_sysattr_value(names
->pcidev
, "acpi_index", &attr
) < 0) {
175 /* SMBIOS type 41 — Onboard Devices Extended Information */
176 r
= sd_device_get_sysattr_value(names
->pcidev
, "index", &attr
);
181 r
= safe_atolu(attr
, &idx
);
184 if (idx
== 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX
))
187 /* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to
188 * report for example). Let's define a cut-off where we don't consider the index reliable anymore. We
189 * pick some arbitrary cut-off, which is somewhere beyond the realistic number of physical network
190 * interface a system might have. Ideally the kernel would already filter his crap for us, but it
191 * doesn't currently. */
192 if (idx
> ONBOARD_INDEX_MAX
)
195 /* kernel provided port index for multiple ports on a single PCI function */
196 if (sd_device_get_sysattr_value(dev
, "dev_port", &attr
) >= 0)
197 dev_port
= strtoul(attr
, NULL
, 10);
199 /* kernel provided front panel port name for multiple port PCI device */
200 (void) sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
202 s
= names
->pci_onboard
;
203 l
= sizeof(names
->pci_onboard
);
204 l
= strpcpyf(&s
, l
, "o%lu", idx
);
206 l
= strpcpyf(&s
, l
, "n%s", port_name
);
207 else if (dev_port
> 0)
208 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
210 names
->pci_onboard
[0] = '\0';
212 if (sd_device_get_sysattr_value(names
->pcidev
, "label", &names
->pci_onboard_label
) < 0)
213 names
->pci_onboard_label
= NULL
;
218 /* read the 256 bytes PCI configuration space to check the multi-function bit */
219 static bool is_pci_multifunction(sd_device
*dev
) {
220 _cleanup_close_
int fd
= -1;
221 const char *filename
, *syspath
;
224 if (sd_device_get_syspath(dev
, &syspath
) < 0)
227 filename
= strjoina(syspath
, "/config");
228 fd
= open(filename
, O_RDONLY
| O_CLOEXEC
);
231 if (read(fd
, &config
, sizeof(config
)) != sizeof(config
))
234 /* bit 0-6 header type, bit 7 multi/single function device */
235 return config
[PCI_HEADER_TYPE
] & 0x80;
238 static bool is_pci_ari_enabled(sd_device
*dev
) {
241 if (sd_device_get_sysattr_value(dev
, "ari_enabled", &a
) < 0)
244 return streq(a
, "1");
247 static int dev_pci_slot(sd_device
*dev
, struct netnames
*names
) {
248 unsigned long dev_port
= 0;
249 unsigned domain
, bus
, slot
, func
, hotplug_slot
= 0;
252 const char *sysname
, *attr
, *port_name
= NULL
, *syspath
;
253 _cleanup_(sd_device_unrefp
) sd_device
*pci
= NULL
;
254 sd_device
*hotplug_slot_dev
;
255 char slots
[PATH_MAX
];
256 _cleanup_closedir_
DIR *dir
= NULL
;
260 r
= sd_device_get_sysname(names
->pcidev
, &sysname
);
264 if (sscanf(sysname
, "%x:%x:%x.%u", &domain
, &bus
, &slot
, &func
) != 4)
267 if (naming_scheme_has(NAMING_NPAR_ARI
) &&
268 is_pci_ari_enabled(names
->pcidev
))
269 /* ARI devices support up to 256 functions on a single device ("slot"), and interpret the
270 * traditional 5-bit slot and 3-bit function number as a single 8-bit function number,
271 * where the slot makes up the upper 5 bits. */
274 /* kernel provided port index for multiple ports on a single PCI function */
275 if (sd_device_get_sysattr_value(dev
, "dev_port", &attr
) >= 0) {
276 dev_port
= strtoul(attr
, NULL
, 10);
277 /* With older kernels IP-over-InfiniBand network interfaces sometimes erroneously
278 * provide the port number in the 'dev_id' sysfs attribute instead of 'dev_port',
279 * which thus stays initialized as 0. */
281 sd_device_get_sysattr_value(dev
, "type", &attr
) >= 0) {
284 type
= strtoul(attr
, NULL
, 10);
285 if (type
== ARPHRD_INFINIBAND
&&
286 sd_device_get_sysattr_value(dev
, "dev_id", &attr
) >= 0)
287 dev_port
= strtoul(attr
, NULL
, 16);
291 /* kernel provided front panel port name for multi-port PCI device */
292 (void) sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
294 /* compose a name based on the raw kernel's PCI bus, slot numbers */
296 l
= sizeof(names
->pci_path
);
298 l
= strpcpyf(&s
, l
, "P%u", domain
);
299 l
= strpcpyf(&s
, l
, "p%us%u", bus
, slot
);
300 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
301 l
= strpcpyf(&s
, l
, "f%u", func
);
303 l
= strpcpyf(&s
, l
, "n%s", port_name
);
304 else if (dev_port
> 0)
305 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
307 names
->pci_path
[0] = '\0';
309 /* ACPI _SUN — slot user number */
310 r
= sd_device_new_from_subsystem_sysname(&pci
, "subsystem", "pci");
314 r
= sd_device_get_syspath(pci
, &syspath
);
317 if (!snprintf_ok(slots
, sizeof slots
, "%s/slots", syspath
))
318 return -ENAMETOOLONG
;
320 dir
= opendir(slots
);
324 hotplug_slot_dev
= names
->pcidev
;
325 while (hotplug_slot_dev
) {
326 if (sd_device_get_sysname(hotplug_slot_dev
, &sysname
) < 0)
329 FOREACH_DIRENT_ALL(dent
, dir
, break) {
332 _cleanup_free_
char *address
= NULL
;
334 if (dent
->d_name
[0] == '.')
336 r
= safe_atou_full(dent
->d_name
, 10, &i
);
340 /* match slot address with device by stripping the function */
341 if (snprintf_ok(str
, sizeof str
, "%s/%s/address", slots
, dent
->d_name
) &&
342 read_one_line_file(str
, &address
) >= 0 &&
343 startswith(sysname
, address
)) {
348 if (hotplug_slot
> 0)
350 if (sd_device_get_parent_with_subsystem_devtype(hotplug_slot_dev
, "pci", NULL
, &hotplug_slot_dev
) < 0)
355 if (hotplug_slot
> 0) {
357 l
= sizeof(names
->pci_slot
);
359 l
= strpcpyf(&s
, l
, "P%d", domain
);
360 l
= strpcpyf(&s
, l
, "s%d", hotplug_slot
);
361 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
362 l
= strpcpyf(&s
, l
, "f%d", func
);
364 l
= strpcpyf(&s
, l
, "n%s", port_name
);
365 else if (dev_port
> 0)
366 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
368 names
->pci_slot
[0] = '\0';
374 static int names_vio(sd_device
*dev
, struct netnames
*names
) {
376 unsigned busid
, slotid
, ethid
;
377 const char *syspath
, *subsystem
;
380 /* check if our direct parent is a VIO device with no other bus in-between */
381 r
= sd_device_get_parent(dev
, &parent
);
385 r
= sd_device_get_subsystem(parent
, &subsystem
);
388 if (!streq("vio", subsystem
))
391 /* The devices' $DEVPATH number is tied to (virtual) hardware (slot id
392 * selected in the HMC), thus this provides a reliable naming (e.g.
393 * "/devices/vio/30000002/net/eth1"); we ignore the bus number, as
394 * there should only ever be one bus, and then remove leading zeros. */
395 r
= sd_device_get_syspath(dev
, &syspath
);
399 if (sscanf(syspath
, "/sys/devices/vio/%4x%4x/net/eth%u", &busid
, &slotid
, ðid
) != 3)
402 xsprintf(names
->vio_slot
, "v%u", slotid
);
403 names
->type
= NET_VIO
;
407 #define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
408 #define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
409 #define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
411 static int names_platform(sd_device
*dev
, struct netnames
*names
, bool test
) {
414 unsigned model
, instance
, ethid
;
415 const char *syspath
, *pattern
, *validchars
, *subsystem
;
418 /* check if our direct parent is a platform device with no other bus in-between */
419 r
= sd_device_get_parent(dev
, &parent
);
423 r
= sd_device_get_subsystem(parent
, &subsystem
);
427 if (!streq("platform", subsystem
))
430 r
= sd_device_get_syspath(dev
, &syspath
);
434 /* syspath is too short, to have a valid ACPI instance */
435 if (strlen(syspath
) < sizeof _PLATFORM_TEST
)
438 /* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
439 if (syspath
[sizeof _PLATFORM_TEST
- 1] == ':') {
440 pattern
= _PLATFORM_PATTERN4
;
441 validchars
= UPPERCASE_LETTERS DIGITS
;
443 pattern
= _PLATFORM_PATTERN3
;
444 validchars
= UPPERCASE_LETTERS
;
447 /* Platform devices are named after ACPI table match, and instance id
448 * eg. "/sys/devices/platform/HISI00C2:00");
449 * The Vendor (3 or 4 char), followed by hexdecimal model number : instance id.
452 #pragma GCC diagnostic push
453 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
454 if (sscanf(syspath
, pattern
, vendor
, &model
, &instance
, ðid
) != 4)
456 #pragma GCC diagnostic pop
458 if (!in_charset(vendor
, validchars
))
461 ascii_strlower(vendor
);
463 xsprintf(names
->platform_path
, "a%s%xi%u", vendor
, model
, instance
);
464 names
->type
= NET_PLATFORM
;
468 static int names_pci(sd_device
*dev
, struct netnames
*names
) {
470 struct netnames vf_names
= {};
471 struct virtfn_info vf_info
= {};
472 const char *subsystem
;
478 r
= sd_device_get_parent(dev
, &parent
);
481 /* skip virtio subsystem if present */
482 parent
= skip_virtio(parent
);
487 /* check if our direct parent is a PCI device with no other bus in-between */
488 if (sd_device_get_subsystem(parent
, &subsystem
) >= 0 &&
489 streq("pci", subsystem
)) {
490 names
->type
= NET_PCI
;
491 names
->pcidev
= parent
;
493 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "pci", NULL
, &names
->pcidev
);
498 if (naming_scheme_has(NAMING_SR_IOV_V
) &&
499 get_virtfn_info(dev
, names
, &vf_info
) >= 0) {
500 /* If this is an SR-IOV virtual device, get base name using physical device and add virtfn suffix. */
501 vf_names
.pcidev
= vf_info
.physfn_pcidev
;
502 dev_pci_onboard(dev
, &vf_names
);
503 dev_pci_slot(dev
, &vf_names
);
504 if (vf_names
.pci_onboard
[0])
505 if (strlen(vf_names
.pci_onboard
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_onboard
))
506 strscpyl(names
->pci_onboard
, sizeof(names
->pci_onboard
),
507 vf_names
.pci_onboard
, vf_info
.suffix
, NULL
);
508 if (vf_names
.pci_slot
[0])
509 if (strlen(vf_names
.pci_slot
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_slot
))
510 strscpyl(names
->pci_slot
, sizeof(names
->pci_slot
),
511 vf_names
.pci_slot
, vf_info
.suffix
, NULL
);
512 if (vf_names
.pci_path
[0])
513 if (strlen(vf_names
.pci_path
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_path
))
514 strscpyl(names
->pci_path
, sizeof(names
->pci_path
),
515 vf_names
.pci_path
, vf_info
.suffix
, NULL
);
516 sd_device_unref(vf_info
.physfn_pcidev
);
518 dev_pci_onboard(dev
, names
);
519 dev_pci_slot(dev
, names
);
525 static int names_usb(sd_device
*dev
, struct netnames
*names
) {
527 char name
[256], *ports
, *config
, *interf
, *s
;
535 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "usb", "usb_interface", &usbdev
);
539 r
= sd_device_get_sysname(usbdev
, &sysname
);
543 /* get USB port number chain, configuration, interface */
544 strscpy(name
, sizeof(name
), sysname
);
545 s
= strchr(name
, '-');
550 s
= strchr(ports
, ':');
556 s
= strchr(config
, '.');
562 /* prefix every port number in the chain with "u" */
564 while ((s
= strchr(s
, '.')))
566 s
= names
->usb_ports
;
567 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "u", ports
, NULL
);
569 /* append USB config number, suppress the common config == 1 */
570 if (!streq(config
, "1"))
571 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "c", config
, NULL
);
573 /* append USB interface number, suppress the interface == 0 */
574 if (!streq(interf
, "0"))
575 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "i", interf
, NULL
);
577 return -ENAMETOOLONG
;
579 names
->type
= NET_USB
;
583 static int names_bcma(sd_device
*dev
, struct netnames
*names
) {
592 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "bcma", NULL
, &bcmadev
);
596 r
= sd_device_get_sysname(bcmadev
, &sysname
);
600 /* bus num:core num */
601 if (sscanf(sysname
, "bcma%*u:%u", &core
) != 1)
603 /* suppress the common core == 0 */
605 xsprintf(names
->bcma_core
, "b%u", core
);
607 names
->type
= NET_BCMA
;
611 static int names_ccw(sd_device
*dev
, struct netnames
*names
) {
613 const char *bus_id
, *subsys
;
621 /* Retrieve the associated CCW device */
622 r
= sd_device_get_parent(dev
, &cdev
);
626 /* skip virtio subsystem if present */
627 cdev
= skip_virtio(cdev
);
631 r
= sd_device_get_subsystem(cdev
, &subsys
);
635 /* Network devices are either single or grouped CCW devices */
636 if (!STR_IN_SET(subsys
, "ccwgroup", "ccw"))
639 /* Retrieve bus-ID of the CCW device. The bus-ID uniquely
640 * identifies the network device on the Linux on System z channel
641 * subsystem. Note that the bus-ID contains lowercase characters.
643 r
= sd_device_get_sysname(cdev
, &bus_id
);
647 /* Check the length of the bus-ID. Rely on the fact that the kernel provides a correct bus-ID;
648 * alternatively, improve this check and parse and verify each bus-ID part...
650 bus_id_len
= strlen(bus_id
);
651 if (!IN_SET(bus_id_len
, 8, 9))
654 /* Strip leading zeros from the bus id for aesthetic purposes. This
655 * keeps the ccw names stable, yet much shorter in general case of
656 * bus_id 0.0.0600 -> 600. This is similar to e.g. how PCI domain is
657 * not prepended when it is zero. Preserve the last 0 for 0.0.0000.
659 bus_id_start
= strspn(bus_id
, ".0");
660 bus_id
+= bus_id_start
< bus_id_len
? bus_id_start
: bus_id_len
- 1;
662 /* Store the CCW bus-ID for use as network device name */
663 if (snprintf_ok(names
->ccw_busid
, sizeof(names
->ccw_busid
), "c%s", bus_id
))
664 names
->type
= NET_CCW
;
669 static int names_mac(sd_device
*dev
, struct netnames
*names
) {
672 unsigned a1
, a2
, a3
, a4
, a5
, a6
;
675 /* Some kinds of devices tend to have hardware addresses
676 * that are impossible to use in an iface name.
678 r
= sd_device_get_sysattr_value(dev
, "type", &s
);
682 i
= strtoul(s
, NULL
, 0);
684 /* The persistent part of a hardware address of an InfiniBand NIC
685 * is 8 bytes long. We cannot fit this much in an iface name.
687 case ARPHRD_INFINIBAND
:
693 /* check for NET_ADDR_PERM, skip random MAC addresses */
694 r
= sd_device_get_sysattr_value(dev
, "addr_assign_type", &s
);
697 i
= strtoul(s
, NULL
, 0);
701 r
= sd_device_get_sysattr_value(dev
, "address", &s
);
704 if (sscanf(s
, "%x:%x:%x:%x:%x:%x", &a1
, &a2
, &a3
, &a4
, &a5
, &a6
) != 6)
707 /* skip empty MAC addresses */
708 if (a1
+ a2
+ a3
+ a4
+ a5
+ a6
== 0)
717 names
->mac_valid
= true;
721 static int names_netdevsim(sd_device
*dev
, struct netnames
*names
) {
722 sd_device
*netdevsimdev
;
725 const char *port_name
= NULL
;
729 if (!naming_scheme_has(NAMING_NETDEVSIM
))
735 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "netdevsim", NULL
, &netdevsimdev
);
738 r
= sd_device_get_sysname(netdevsimdev
, &sysname
);
742 if (sscanf(sysname
, "netdevsim%u", &addr
) != 1)
745 r
= sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
749 ok
= snprintf_ok(names
->netdevsim_path
, sizeof(names
->netdevsim_path
), "i%un%s", addr
, port_name
);
753 names
->type
= NET_NETDEVSIM
;
758 /* IEEE Organizationally Unique Identifier vendor string */
759 static int ieee_oui(sd_device
*dev
, struct netnames
*names
, bool test
) {
762 if (!names
->mac_valid
)
764 /* skip commonly misused 00:00:00 (Xerox) prefix */
765 if (memcmp(names
->mac
, "\0\0\0", 3) == 0)
767 xsprintf(str
, "OUI:%02X%02X%02X%02X%02X%02X", names
->mac
[0],
768 names
->mac
[1], names
->mac
[2], names
->mac
[3], names
->mac
[4],
770 udev_builtin_hwdb_lookup(dev
, NULL
, str
, NULL
, test
);
774 static int builtin_net_id(sd_device
*dev
, int argc
, char *argv
[], bool test
) {
775 const char *s
, *p
, *devtype
, *prefix
= "en";
776 struct netnames names
= {};
780 /* handle only ARPHRD_ETHER, ARPHRD_SLIP and ARPHRD_INFINIBAND devices */
781 r
= sd_device_get_sysattr_value(dev
, "type", &s
);
785 i
= strtoul(s
, NULL
, 0);
790 case ARPHRD_INFINIBAND
:
791 if (naming_scheme_has(NAMING_INFINIBAND
))
803 /* skip stacked devices, like VLANs, ... */
804 r
= sd_device_get_sysattr_value(dev
, "ifindex", &s
);
807 r
= sd_device_get_sysattr_value(dev
, "iflink", &p
);
813 if (sd_device_get_devtype(dev
, &devtype
) >= 0) {
814 if (streq("wlan", devtype
))
816 else if (streq("wwan", devtype
))
820 udev_builtin_add_property(dev
, test
, "ID_NET_NAMING_SCHEME", naming_scheme()->name
);
822 r
= names_mac(dev
, &names
);
823 if (r
>= 0 && names
.mac_valid
) {
826 xsprintf(str
, "%sx%02x%02x%02x%02x%02x%02x", prefix
,
827 names
.mac
[0], names
.mac
[1], names
.mac
[2],
828 names
.mac
[3], names
.mac
[4], names
.mac
[5]);
829 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_MAC", str
);
831 ieee_oui(dev
, &names
, test
);
834 /* get path names for Linux on System z network devices */
835 if (names_ccw(dev
, &names
) >= 0 && names
.type
== NET_CCW
) {
838 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.ccw_busid
))
839 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
843 /* get ibmveth/ibmvnic slot-based names. */
844 if (names_vio(dev
, &names
) >= 0 && names
.type
== NET_VIO
) {
847 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.vio_slot
))
848 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
852 /* get ACPI path names for ARM64 platform devices */
853 if (names_platform(dev
, &names
, test
) >= 0 && names
.type
== NET_PLATFORM
) {
856 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.platform_path
))
857 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
861 /* get netdevsim path names */
862 if (names_netdevsim(dev
, &names
) >= 0 && names
.type
== NET_NETDEVSIM
) {
865 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.netdevsim_path
))
866 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
871 /* get PCI based path names, we compose only PCI based paths */
872 if (names_pci(dev
, &names
) < 0)
875 /* plain PCI device */
876 if (names
.type
== NET_PCI
) {
879 if (names
.pci_onboard
[0] &&
880 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_onboard
))
881 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_ONBOARD", str
);
883 if (names
.pci_onboard_label
&&
884 snprintf_ok(str
, sizeof str
, "%s%s",
885 naming_scheme_has(NAMING_LABEL_NOPREFIX
) ? "" : prefix
,
886 names
.pci_onboard_label
))
887 udev_builtin_add_property(dev
, test
, "ID_NET_LABEL_ONBOARD", str
);
889 if (names
.pci_path
[0] &&
890 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_path
))
891 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
893 if (names
.pci_slot
[0] &&
894 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_slot
))
895 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
900 if (names_usb(dev
, &names
) >= 0 && names
.type
== NET_USB
) {
903 if (names
.pci_path
[0] &&
904 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.usb_ports
))
905 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
907 if (names
.pci_slot
[0] &&
908 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.usb_ports
))
909 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
914 if (names_bcma(dev
, &names
) >= 0 && names
.type
== NET_BCMA
) {
917 if (names
.pci_path
[0] &&
918 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.bcma_core
))
919 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
921 if (names
.pci_slot
[0] &&
922 snprintf(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.bcma_core
))
923 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
930 const UdevBuiltin udev_builtin_net_id
= {
932 .cmd
= builtin_net_id
,
933 .help
= "Network device properties",