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 * https://systemd.io/PREDICTABLE_INTERFACE_NAMES
12 * When the code here is changed, man/systemd.net-naming-scheme.xml must be updated too.
18 #include <net/if_arp.h>
23 #include <linux/pci_regs.h>
25 #include "alloc-util.h"
26 #include "dirent-util.h"
30 #include "naming-scheme.h"
31 #include "parse-util.h"
32 #include "proc-cmdline.h"
33 #include "stdio-util.h"
34 #include "string-util.h"
37 #include "udev-builtin.h"
39 #define ONBOARD_INDEX_MAX (16*1024-1)
54 enum netname_type type
;
60 char pci_slot
[ALTIFNAMSIZ
];
61 char pci_path
[ALTIFNAMSIZ
];
62 char pci_onboard
[ALTIFNAMSIZ
];
63 const char *pci_onboard_label
;
65 char usb_ports
[ALTIFNAMSIZ
];
66 char bcma_core
[ALTIFNAMSIZ
];
67 char ccw_busid
[ALTIFNAMSIZ
];
68 char vio_slot
[ALTIFNAMSIZ
];
69 char platform_path
[ALTIFNAMSIZ
];
70 char netdevsim_path
[ALTIFNAMSIZ
];
74 sd_device
*physfn_pcidev
;
75 char suffix
[ALTIFNAMSIZ
];
78 /* skip intermediate virtio devices */
79 static sd_device
*skip_virtio(sd_device
*dev
) {
82 /* there can only ever be one virtio bus per parent device, so we can
83 * safely ignore any virtio buses. see
84 * http://lists.linuxfoundation.org/pipermail/virtualization/2015-August/030331.html */
85 for (parent
= dev
; parent
; ) {
86 const char *subsystem
;
88 if (sd_device_get_subsystem(parent
, &subsystem
) < 0)
91 if (!streq(subsystem
, "virtio"))
94 if (sd_device_get_parent(parent
, &parent
) < 0)
101 static int get_virtfn_info(sd_device
*dev
, struct netnames
*names
, struct virtfn_info
*ret
) {
102 _cleanup_(sd_device_unrefp
) sd_device
*physfn_pcidev
= NULL
;
103 const char *physfn_link_file
, *syspath
;
104 _cleanup_free_
char *physfn_pci_syspath
= NULL
;
105 _cleanup_free_
char *virtfn_pci_syspath
= NULL
;
107 _cleanup_closedir_
DIR *dir
= NULL
;
108 char suffix
[ALTIFNAMSIZ
];
115 r
= sd_device_get_syspath(names
->pcidev
, &syspath
);
119 /* Check if this is a virtual function. */
120 physfn_link_file
= strjoina(syspath
, "/physfn");
121 r
= chase_symlinks(physfn_link_file
, NULL
, 0, &physfn_pci_syspath
, NULL
);
125 /* Get physical function's pci device. */
126 r
= sd_device_new_from_syspath(&physfn_pcidev
, physfn_pci_syspath
);
130 /* Find the virtual function number by finding the right virtfn link. */
131 dir
= opendir(physfn_pci_syspath
);
135 FOREACH_DIRENT_ALL(dent
, dir
, break) {
136 _cleanup_free_
char *virtfn_link_file
= NULL
;
138 if (!startswith(dent
->d_name
, "virtfn"))
141 virtfn_link_file
= path_join(physfn_pci_syspath
, dent
->d_name
);
142 if (!virtfn_link_file
)
145 if (chase_symlinks(virtfn_link_file
, NULL
, 0, &virtfn_pci_syspath
, NULL
) < 0)
148 if (streq(syspath
, virtfn_pci_syspath
)) {
149 if (!snprintf_ok(suffix
, sizeof(suffix
), "v%s", &dent
->d_name
[6]))
158 ret
->physfn_pcidev
= TAKE_PTR(physfn_pcidev
);
159 strncpy(ret
->suffix
, suffix
, sizeof(ret
->suffix
));
164 /* retrieve on-board index number and label from firmware */
165 static int dev_pci_onboard(sd_device
*dev
, struct netnames
*names
) {
166 unsigned long idx
, dev_port
= 0;
167 const char *attr
, *port_name
= NULL
;
172 /* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
173 if (sd_device_get_sysattr_value(names
->pcidev
, "acpi_index", &attr
) < 0) {
174 /* SMBIOS type 41 — Onboard Devices Extended Information */
175 r
= sd_device_get_sysattr_value(names
->pcidev
, "index", &attr
);
180 r
= safe_atolu(attr
, &idx
);
183 if (idx
== 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX
))
186 /* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to
187 * report for example). Let's define a cut-off where we don't consider the index reliable anymore. We
188 * pick some arbitrary cut-off, which is somewhere beyond the realistic number of physical network
189 * interface a system might have. Ideally the kernel would already filter his crap for us, but it
190 * doesn't currently. */
191 if (idx
> ONBOARD_INDEX_MAX
)
194 /* kernel provided port index for multiple ports on a single PCI function */
195 if (sd_device_get_sysattr_value(dev
, "dev_port", &attr
) >= 0)
196 dev_port
= strtoul(attr
, NULL
, 10);
198 /* kernel provided front panel port name for multiple port PCI device */
199 (void) sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
201 s
= names
->pci_onboard
;
202 l
= sizeof(names
->pci_onboard
);
203 l
= strpcpyf(&s
, l
, "o%lu", idx
);
205 l
= strpcpyf(&s
, l
, "n%s", port_name
);
206 else if (dev_port
> 0)
207 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
209 names
->pci_onboard
[0] = '\0';
211 if (sd_device_get_sysattr_value(names
->pcidev
, "label", &names
->pci_onboard_label
) < 0)
212 names
->pci_onboard_label
= NULL
;
217 /* read the 256 bytes PCI configuration space to check the multi-function bit */
218 static bool is_pci_multifunction(sd_device
*dev
) {
219 _cleanup_close_
int fd
= -1;
220 const char *filename
, *syspath
;
223 if (sd_device_get_syspath(dev
, &syspath
) < 0)
226 filename
= strjoina(syspath
, "/config");
227 fd
= open(filename
, O_RDONLY
| O_CLOEXEC
);
230 if (read(fd
, &config
, sizeof(config
)) != sizeof(config
))
233 /* bit 0-6 header type, bit 7 multi/single function device */
234 return config
[PCI_HEADER_TYPE
] & 0x80;
237 static bool is_pci_ari_enabled(sd_device
*dev
) {
240 if (sd_device_get_sysattr_value(dev
, "ari_enabled", &a
) < 0)
243 return streq(a
, "1");
246 static int dev_pci_slot(sd_device
*dev
, struct netnames
*names
) {
247 unsigned long dev_port
= 0;
248 unsigned domain
, bus
, slot
, func
, hotplug_slot
= 0;
251 const char *sysname
, *attr
, *port_name
= NULL
, *syspath
;
252 _cleanup_(sd_device_unrefp
) sd_device
*pci
= NULL
;
253 sd_device
*hotplug_slot_dev
;
254 char slots
[PATH_MAX
];
255 _cleanup_closedir_
DIR *dir
= NULL
;
259 r
= sd_device_get_sysname(names
->pcidev
, &sysname
);
263 if (sscanf(sysname
, "%x:%x:%x.%u", &domain
, &bus
, &slot
, &func
) != 4)
266 if (naming_scheme_has(NAMING_NPAR_ARI
) &&
267 is_pci_ari_enabled(names
->pcidev
))
268 /* ARI devices support up to 256 functions on a single device ("slot"), and interpret the
269 * traditional 5-bit slot and 3-bit function number as a single 8-bit function number,
270 * where the slot makes up the upper 5 bits. */
273 /* kernel provided port index for multiple ports on a single PCI function */
274 if (sd_device_get_sysattr_value(dev
, "dev_port", &attr
) >= 0) {
275 dev_port
= strtoul(attr
, NULL
, 10);
276 /* With older kernels IP-over-InfiniBand network interfaces sometimes erroneously
277 * provide the port number in the 'dev_id' sysfs attribute instead of 'dev_port',
278 * which thus stays initialized as 0. */
280 sd_device_get_sysattr_value(dev
, "type", &attr
) >= 0) {
283 type
= strtoul(attr
, NULL
, 10);
284 if (type
== ARPHRD_INFINIBAND
&&
285 sd_device_get_sysattr_value(dev
, "dev_id", &attr
) >= 0)
286 dev_port
= strtoul(attr
, NULL
, 16);
290 /* kernel provided front panel port name for multi-port PCI device */
291 (void) sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
293 /* compose a name based on the raw kernel's PCI bus, slot numbers */
295 l
= sizeof(names
->pci_path
);
297 l
= strpcpyf(&s
, l
, "P%u", domain
);
298 l
= strpcpyf(&s
, l
, "p%us%u", bus
, slot
);
299 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
300 l
= strpcpyf(&s
, l
, "f%u", func
);
302 l
= strpcpyf(&s
, l
, "n%s", port_name
);
303 else if (dev_port
> 0)
304 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
306 names
->pci_path
[0] = '\0';
308 /* ACPI _SUN — slot user number */
309 r
= sd_device_new_from_subsystem_sysname(&pci
, "subsystem", "pci");
313 r
= sd_device_get_syspath(pci
, &syspath
);
316 if (!snprintf_ok(slots
, sizeof slots
, "%s/slots", syspath
))
317 return -ENAMETOOLONG
;
319 dir
= opendir(slots
);
323 hotplug_slot_dev
= names
->pcidev
;
324 while (hotplug_slot_dev
) {
325 if (sd_device_get_sysname(hotplug_slot_dev
, &sysname
) < 0)
328 FOREACH_DIRENT_ALL(dent
, dir
, break) {
331 _cleanup_free_
char *address
= NULL
;
333 if (dent
->d_name
[0] == '.')
335 r
= safe_atou_full(dent
->d_name
, 10, &i
);
339 /* match slot address with device by stripping the function */
340 if (snprintf_ok(str
, sizeof str
, "%s/%s/address", slots
, dent
->d_name
) &&
341 read_one_line_file(str
, &address
) >= 0 &&
342 startswith(sysname
, address
)) {
347 if (hotplug_slot
> 0)
349 if (sd_device_get_parent_with_subsystem_devtype(hotplug_slot_dev
, "pci", NULL
, &hotplug_slot_dev
) < 0)
354 if (hotplug_slot
> 0) {
356 l
= sizeof(names
->pci_slot
);
358 l
= strpcpyf(&s
, l
, "P%d", domain
);
359 l
= strpcpyf(&s
, l
, "s%d", hotplug_slot
);
360 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
361 l
= strpcpyf(&s
, l
, "f%d", func
);
363 l
= strpcpyf(&s
, l
, "n%s", port_name
);
364 else if (dev_port
> 0)
365 l
= strpcpyf(&s
, l
, "d%lu", dev_port
);
367 names
->pci_slot
[0] = '\0';
373 static int names_vio(sd_device
*dev
, struct netnames
*names
) {
375 unsigned busid
, slotid
, ethid
;
376 const char *syspath
, *subsystem
;
379 /* check if our direct parent is a VIO device with no other bus in-between */
380 r
= sd_device_get_parent(dev
, &parent
);
384 r
= sd_device_get_subsystem(parent
, &subsystem
);
387 if (!streq("vio", subsystem
))
390 /* The devices' $DEVPATH number is tied to (virtual) hardware (slot id
391 * selected in the HMC), thus this provides a reliable naming (e.g.
392 * "/devices/vio/30000002/net/eth1"); we ignore the bus number, as
393 * there should only ever be one bus, and then remove leading zeros. */
394 r
= sd_device_get_syspath(dev
, &syspath
);
398 if (sscanf(syspath
, "/sys/devices/vio/%4x%4x/net/eth%u", &busid
, &slotid
, ðid
) != 3)
401 xsprintf(names
->vio_slot
, "v%u", slotid
);
402 names
->type
= NET_VIO
;
406 #define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
407 #define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
408 #define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
410 static int names_platform(sd_device
*dev
, struct netnames
*names
, bool test
) {
413 unsigned model
, instance
, ethid
;
414 const char *syspath
, *pattern
, *validchars
, *subsystem
;
417 /* check if our direct parent is a platform device with no other bus in-between */
418 r
= sd_device_get_parent(dev
, &parent
);
422 r
= sd_device_get_subsystem(parent
, &subsystem
);
426 if (!streq("platform", subsystem
))
429 r
= sd_device_get_syspath(dev
, &syspath
);
433 /* syspath is too short, to have a valid ACPI instance */
434 if (strlen(syspath
) < sizeof _PLATFORM_TEST
)
437 /* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
438 if (syspath
[sizeof _PLATFORM_TEST
- 1] == ':') {
439 pattern
= _PLATFORM_PATTERN4
;
440 validchars
= UPPERCASE_LETTERS DIGITS
;
442 pattern
= _PLATFORM_PATTERN3
;
443 validchars
= UPPERCASE_LETTERS
;
446 /* Platform devices are named after ACPI table match, and instance id
447 * eg. "/sys/devices/platform/HISI00C2:00");
448 * The Vendor (3 or 4 char), followed by hexdecimal model number : instance id.
451 #pragma GCC diagnostic push
452 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
453 if (sscanf(syspath
, pattern
, vendor
, &model
, &instance
, ðid
) != 4)
455 #pragma GCC diagnostic pop
457 if (!in_charset(vendor
, validchars
))
460 ascii_strlower(vendor
);
462 xsprintf(names
->platform_path
, "a%s%xi%u", vendor
, model
, instance
);
463 names
->type
= NET_PLATFORM
;
467 static int names_pci(sd_device
*dev
, struct netnames
*names
) {
469 struct netnames vf_names
= {};
470 struct virtfn_info vf_info
= {};
471 const char *subsystem
;
477 r
= sd_device_get_parent(dev
, &parent
);
480 /* skip virtio subsystem if present */
481 parent
= skip_virtio(parent
);
486 /* check if our direct parent is a PCI device with no other bus in-between */
487 if (sd_device_get_subsystem(parent
, &subsystem
) >= 0 &&
488 streq("pci", subsystem
)) {
489 names
->type
= NET_PCI
;
490 names
->pcidev
= parent
;
492 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "pci", NULL
, &names
->pcidev
);
497 if (naming_scheme_has(NAMING_SR_IOV_V
) &&
498 get_virtfn_info(dev
, names
, &vf_info
) >= 0) {
499 /* If this is an SR-IOV virtual device, get base name using physical device and add virtfn suffix. */
500 vf_names
.pcidev
= vf_info
.physfn_pcidev
;
501 dev_pci_onboard(dev
, &vf_names
);
502 dev_pci_slot(dev
, &vf_names
);
503 if (vf_names
.pci_onboard
[0])
504 if (strlen(vf_names
.pci_onboard
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_onboard
))
505 strscpyl(names
->pci_onboard
, sizeof(names
->pci_onboard
),
506 vf_names
.pci_onboard
, vf_info
.suffix
, NULL
);
507 if (vf_names
.pci_slot
[0])
508 if (strlen(vf_names
.pci_slot
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_slot
))
509 strscpyl(names
->pci_slot
, sizeof(names
->pci_slot
),
510 vf_names
.pci_slot
, vf_info
.suffix
, NULL
);
511 if (vf_names
.pci_path
[0])
512 if (strlen(vf_names
.pci_path
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_path
))
513 strscpyl(names
->pci_path
, sizeof(names
->pci_path
),
514 vf_names
.pci_path
, vf_info
.suffix
, NULL
);
515 sd_device_unref(vf_info
.physfn_pcidev
);
517 dev_pci_onboard(dev
, names
);
518 dev_pci_slot(dev
, names
);
524 static int names_usb(sd_device
*dev
, struct netnames
*names
) {
526 char name
[256], *ports
, *config
, *interf
, *s
;
534 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "usb", "usb_interface", &usbdev
);
538 r
= sd_device_get_sysname(usbdev
, &sysname
);
542 /* get USB port number chain, configuration, interface */
543 strscpy(name
, sizeof(name
), sysname
);
544 s
= strchr(name
, '-');
549 s
= strchr(ports
, ':');
555 s
= strchr(config
, '.');
561 /* prefix every port number in the chain with "u" */
563 while ((s
= strchr(s
, '.')))
565 s
= names
->usb_ports
;
566 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "u", ports
, NULL
);
568 /* append USB config number, suppress the common config == 1 */
569 if (!streq(config
, "1"))
570 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "c", config
, NULL
);
572 /* append USB interface number, suppress the interface == 0 */
573 if (!streq(interf
, "0"))
574 l
= strpcpyl(&s
, sizeof(names
->usb_ports
), "i", interf
, NULL
);
576 return -ENAMETOOLONG
;
578 names
->type
= NET_USB
;
582 static int names_bcma(sd_device
*dev
, struct netnames
*names
) {
591 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "bcma", NULL
, &bcmadev
);
595 r
= sd_device_get_sysname(bcmadev
, &sysname
);
599 /* bus num:core num */
600 if (sscanf(sysname
, "bcma%*u:%u", &core
) != 1)
602 /* suppress the common core == 0 */
604 xsprintf(names
->bcma_core
, "b%u", core
);
606 names
->type
= NET_BCMA
;
610 static int names_ccw(sd_device
*dev
, struct netnames
*names
) {
612 const char *bus_id
, *subsys
;
620 /* Retrieve the associated CCW device */
621 r
= sd_device_get_parent(dev
, &cdev
);
625 /* skip virtio subsystem if present */
626 cdev
= skip_virtio(cdev
);
630 r
= sd_device_get_subsystem(cdev
, &subsys
);
634 /* Network devices are either single or grouped CCW devices */
635 if (!STR_IN_SET(subsys
, "ccwgroup", "ccw"))
638 /* Retrieve bus-ID of the CCW device. The bus-ID uniquely
639 * identifies the network device on the Linux on System z channel
640 * subsystem. Note that the bus-ID contains lowercase characters.
642 r
= sd_device_get_sysname(cdev
, &bus_id
);
646 /* Check the length of the bus-ID. Rely on the fact that the kernel provides a correct bus-ID;
647 * alternatively, improve this check and parse and verify each bus-ID part...
649 bus_id_len
= strlen(bus_id
);
650 if (!IN_SET(bus_id_len
, 8, 9))
653 /* Strip leading zeros from the bus id for aesthetic purposes. This
654 * keeps the ccw names stable, yet much shorter in general case of
655 * bus_id 0.0.0600 -> 600. This is similar to e.g. how PCI domain is
656 * not prepended when it is zero. Preserve the last 0 for 0.0.0000.
658 bus_id_start
= strspn(bus_id
, ".0");
659 bus_id
+= bus_id_start
< bus_id_len
? bus_id_start
: bus_id_len
- 1;
661 /* Store the CCW bus-ID for use as network device name */
662 if (snprintf_ok(names
->ccw_busid
, sizeof(names
->ccw_busid
), "c%s", bus_id
))
663 names
->type
= NET_CCW
;
668 static int names_mac(sd_device
*dev
, struct netnames
*names
) {
671 unsigned a1
, a2
, a3
, a4
, a5
, a6
;
674 /* Some kinds of devices tend to have hardware addresses
675 * that are impossible to use in an iface name.
677 r
= sd_device_get_sysattr_value(dev
, "type", &s
);
681 i
= strtoul(s
, NULL
, 0);
683 /* The persistent part of a hardware address of an InfiniBand NIC
684 * is 8 bytes long. We cannot fit this much in an iface name.
686 case ARPHRD_INFINIBAND
:
692 /* check for NET_ADDR_PERM, skip random MAC addresses */
693 r
= sd_device_get_sysattr_value(dev
, "addr_assign_type", &s
);
696 i
= strtoul(s
, NULL
, 0);
700 r
= sd_device_get_sysattr_value(dev
, "address", &s
);
703 if (sscanf(s
, "%x:%x:%x:%x:%x:%x", &a1
, &a2
, &a3
, &a4
, &a5
, &a6
) != 6)
706 /* skip empty MAC addresses */
707 if (a1
+ a2
+ a3
+ a4
+ a5
+ a6
== 0)
716 names
->mac_valid
= true;
720 static int names_netdevsim(sd_device
*dev
, struct netnames
*names
) {
721 sd_device
*netdevsimdev
;
724 const char *port_name
= NULL
;
728 if (!naming_scheme_has(NAMING_NETDEVSIM
))
734 r
= sd_device_get_parent_with_subsystem_devtype(dev
, "netdevsim", NULL
, &netdevsimdev
);
737 r
= sd_device_get_sysname(netdevsimdev
, &sysname
);
741 if (sscanf(sysname
, "netdevsim%u", &addr
) != 1)
744 r
= sd_device_get_sysattr_value(dev
, "phys_port_name", &port_name
);
748 ok
= snprintf_ok(names
->netdevsim_path
, sizeof(names
->netdevsim_path
), "i%un%s", addr
, port_name
);
752 names
->type
= NET_NETDEVSIM
;
757 /* IEEE Organizationally Unique Identifier vendor string */
758 static int ieee_oui(sd_device
*dev
, struct netnames
*names
, bool test
) {
761 if (!names
->mac_valid
)
763 /* skip commonly misused 00:00:00 (Xerox) prefix */
764 if (memcmp(names
->mac
, "\0\0\0", 3) == 0)
766 xsprintf(str
, "OUI:%02X%02X%02X%02X%02X%02X", names
->mac
[0],
767 names
->mac
[1], names
->mac
[2], names
->mac
[3], names
->mac
[4],
769 udev_builtin_hwdb_lookup(dev
, NULL
, str
, NULL
, test
);
773 static int builtin_net_id(sd_device
*dev
, int argc
, char *argv
[], bool test
) {
774 const char *s
, *p
, *devtype
, *prefix
= "en";
775 struct netnames names
= {};
779 /* handle only ARPHRD_ETHER, ARPHRD_SLIP and ARPHRD_INFINIBAND devices */
780 r
= sd_device_get_sysattr_value(dev
, "type", &s
);
784 i
= strtoul(s
, NULL
, 0);
789 case ARPHRD_INFINIBAND
:
790 if (naming_scheme_has(NAMING_INFINIBAND
))
802 /* skip stacked devices, like VLANs, ... */
803 r
= sd_device_get_sysattr_value(dev
, "ifindex", &s
);
806 r
= sd_device_get_sysattr_value(dev
, "iflink", &p
);
812 if (sd_device_get_devtype(dev
, &devtype
) >= 0) {
813 if (streq("wlan", devtype
))
815 else if (streq("wwan", devtype
))
819 udev_builtin_add_property(dev
, test
, "ID_NET_NAMING_SCHEME", naming_scheme()->name
);
821 r
= names_mac(dev
, &names
);
822 if (r
>= 0 && names
.mac_valid
) {
823 char str
[ALTIFNAMSIZ
];
825 xsprintf(str
, "%sx%02x%02x%02x%02x%02x%02x", prefix
,
826 names
.mac
[0], names
.mac
[1], names
.mac
[2],
827 names
.mac
[3], names
.mac
[4], names
.mac
[5]);
828 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_MAC", str
);
830 ieee_oui(dev
, &names
, test
);
833 /* get path names for Linux on System z network devices */
834 if (names_ccw(dev
, &names
) >= 0 && names
.type
== NET_CCW
) {
835 char str
[ALTIFNAMSIZ
];
837 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.ccw_busid
))
838 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
842 /* get ibmveth/ibmvnic slot-based names. */
843 if (names_vio(dev
, &names
) >= 0 && names
.type
== NET_VIO
) {
844 char str
[ALTIFNAMSIZ
];
846 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.vio_slot
))
847 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
851 /* get ACPI path names for ARM64 platform devices */
852 if (names_platform(dev
, &names
, test
) >= 0 && names
.type
== NET_PLATFORM
) {
853 char str
[ALTIFNAMSIZ
];
855 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.platform_path
))
856 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
860 /* get netdevsim path names */
861 if (names_netdevsim(dev
, &names
) >= 0 && names
.type
== NET_NETDEVSIM
) {
862 char str
[ALTIFNAMSIZ
];
864 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.netdevsim_path
))
865 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
870 /* get PCI based path names, we compose only PCI based paths */
871 if (names_pci(dev
, &names
) < 0)
874 /* plain PCI device */
875 if (names
.type
== NET_PCI
) {
876 char str
[ALTIFNAMSIZ
];
878 if (names
.pci_onboard
[0] &&
879 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_onboard
))
880 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_ONBOARD", str
);
882 if (names
.pci_onboard_label
&&
883 snprintf_ok(str
, sizeof str
, "%s%s",
884 naming_scheme_has(NAMING_LABEL_NOPREFIX
) ? "" : prefix
,
885 names
.pci_onboard_label
))
886 udev_builtin_add_property(dev
, test
, "ID_NET_LABEL_ONBOARD", str
);
888 if (names
.pci_path
[0] &&
889 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_path
))
890 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
892 if (names
.pci_slot
[0] &&
893 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_slot
))
894 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
899 if (names_usb(dev
, &names
) >= 0 && names
.type
== NET_USB
) {
900 char str
[ALTIFNAMSIZ
];
902 if (names
.pci_path
[0] &&
903 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.usb_ports
))
904 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
906 if (names
.pci_slot
[0] &&
907 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.usb_ports
))
908 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
913 if (names_bcma(dev
, &names
) >= 0 && names
.type
== NET_BCMA
) {
914 char str
[ALTIFNAMSIZ
];
916 if (names
.pci_path
[0] &&
917 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.bcma_core
))
918 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
920 if (names
.pci_slot
[0] &&
921 snprintf(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.bcma_core
))
922 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
929 const UdevBuiltin udev_builtin_net_id
= {
931 .cmd
= builtin_net_id
,
932 .help
= "Network device properties",