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 * Two character prefixes based on the type of interface:
14 * sl — serial line IP (slip)
19 * b<number> — BCMA bus core number
20 * c<bus_id> — bus id of a grouped CCW or CCW device,
21 * with all leading zeros stripped [s390]
22 * o<index>[n<phys_port_name>|d<dev_port>]
23 * — on-board device index number
24 * s<slot>[f<function>][n<phys_port_name>|d<dev_port>]
25 * — hotplug slot index number
26 * x<MAC> — MAC address
27 * [P<domain>]p<bus>s<slot>[f<function>][n<phys_port_name>|d<dev_port>]
28 * — PCI geographical location
29 * [P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>]
30 * — USB port number chain
31 * v<slot> - VIO slot number (IBM PowerVM)
32 * a<vendor><model>i<instance> — Platform bus ACPI instance id
34 * All multi-function PCI devices will carry the [f<function>] number in the
35 * device name, including the function 0 device.
37 * SR-IOV virtual devices are named based on the name of the parent interface,
38 * with a suffix of "v<N>", where <N> is the virtual device number.
40 * When using PCI geography, The PCI domain is only prepended when it is not 0.
42 * For USB devices the full chain of port numbers of hubs is composed. If the
43 * name gets longer than the maximum number of 15 characters, the name is not
45 * The usual USB configuration == 1 and interface == 0 values are suppressed.
47 * PCI Ethernet card with firmware index "1":
48 * ID_NET_NAME_ONBOARD=eno1
49 * ID_NET_NAME_ONBOARD_LABEL=Ethernet Port 1
51 * PCI Ethernet card in hotplug slot with firmware index number:
52 * /sys/devices/pci0000:00/0000:00:1c.3/0000:05:00.0/net/ens1
53 * ID_NET_NAME_MAC=enx000000000466
54 * ID_NET_NAME_PATH=enp5s0
55 * ID_NET_NAME_SLOT=ens1
57 * PCI Ethernet multi-function card with 2 ports:
58 * /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/enp2s0f0
59 * ID_NET_NAME_MAC=enx78e7d1ea46da
60 * ID_NET_NAME_PATH=enp2s0f0
61 * /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.1/net/enp2s0f1
62 * ID_NET_NAME_MAC=enx78e7d1ea46dc
63 * ID_NET_NAME_PATH=enp2s0f1
66 * /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlp3s0
67 * ID_NET_NAME_MAC=wlx0024d7e31130
68 * ID_NET_NAME_PATH=wlp3s0
70 * USB built-in 3G modem:
71 * /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.6/net/wwp0s29u1u4i6
72 * ID_NET_NAME_MAC=wwx028037ec0200
73 * ID_NET_NAME_PATH=wwp0s29u1u4i6
76 * /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/net/enp0s29u1u2
77 * ID_NET_NAME_MAC=enxd626b3450fb5
78 * ID_NET_NAME_PATH=enp0s29u1u2
80 * s390 grouped CCW interface:
81 * /sys/devices/css0/0.0.0007/0.0.f5f0/group_device/net/encf5f0
82 * ID_NET_NAME_MAC=enx026d3c00000a
83 * ID_NET_NAME_PATH=encf5f0
89 #include <net/if_arp.h>
95 #include <linux/pci_regs.h>
97 #include "dirent-util.h"
101 #include "parse-util.h"
102 #include "stdio-util.h"
103 #include "string-util.h"
105 #include "udev-util.h"
107 #define ONBOARD_INDEX_MAX (16*1024-1)
121 enum netname_type type
;
126 struct udev_device
*pcidev
;
127 char pci_slot
[IFNAMSIZ
];
128 char pci_path
[IFNAMSIZ
];
129 char pci_onboard
[IFNAMSIZ
];
130 const char *pci_onboard_label
;
132 char usb_ports
[IFNAMSIZ
];
133 char bcma_core
[IFNAMSIZ
];
134 char ccw_busid
[IFNAMSIZ
];
135 char vio_slot
[IFNAMSIZ
];
136 char platform_path
[IFNAMSIZ
];
140 struct udev_device
*physfn_pcidev
;
141 char suffix
[IFNAMSIZ
];
144 /* skip intermediate virtio devices */
145 static struct udev_device
*skip_virtio(struct udev_device
*dev
) {
146 struct udev_device
*parent
= dev
;
148 /* there can only ever be one virtio bus per parent device, so we can
149 safely ignore any virtio buses. see
150 <http://lists.linuxfoundation.org/pipermail/virtualization/2015-August/030331.html> */
151 while (parent
&& streq_ptr("virtio", udev_device_get_subsystem(parent
)))
152 parent
= udev_device_get_parent(parent
);
156 static int get_virtfn_info(struct udev_device
*dev
, struct netnames
*names
, struct virtfn_info
*vf_info
) {
158 const char *physfn_link_file
;
159 _cleanup_free_
char *physfn_pci_syspath
= NULL
;
160 _cleanup_free_
char *virtfn_pci_syspath
= NULL
;
162 _cleanup_closedir_
DIR *dir
= NULL
;
163 struct virtfn_info vf_info_local
= {};
166 udev
= udev_device_get_udev(names
->pcidev
);
169 /* Check if this is a virtual function. */
170 physfn_link_file
= strjoina(udev_device_get_syspath(names
->pcidev
), "/physfn");
171 r
= chase_symlinks(physfn_link_file
, NULL
, 0, &physfn_pci_syspath
);
175 /* Get physical function's pci device. */
176 vf_info_local
.physfn_pcidev
= udev_device_new_from_syspath(udev
, physfn_pci_syspath
);
177 if (!vf_info_local
.physfn_pcidev
)
180 /* Find the virtual function number by finding the right virtfn link. */
181 dir
= opendir(physfn_pci_syspath
);
186 FOREACH_DIRENT_ALL(dent
, dir
, break) {
187 _cleanup_free_
char *virtfn_link_file
= NULL
;
188 if (!startswith(dent
->d_name
, "virtfn"))
190 virtfn_link_file
= strjoin(physfn_pci_syspath
, "/", dent
->d_name
);
191 if (!virtfn_link_file
) {
195 if (chase_symlinks(virtfn_link_file
, NULL
, 0, &virtfn_pci_syspath
) < 0)
197 if (streq(udev_device_get_syspath(names
->pcidev
), virtfn_pci_syspath
)) {
198 if (!snprintf_ok(vf_info_local
.suffix
, sizeof(vf_info_local
.suffix
), "v%s", &dent
->d_name
[6])) {
205 if (isempty(vf_info_local
.suffix
)) {
209 *vf_info
= vf_info_local
;
213 udev_device_unref(vf_info_local
.physfn_pcidev
);
217 /* retrieve on-board index number and label from firmware */
218 static int dev_pci_onboard(struct udev_device
*dev
, struct netnames
*names
) {
219 unsigned dev_port
= 0;
222 const char *attr
, *port_name
;
225 /* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
226 attr
= udev_device_get_sysattr_value(names
->pcidev
, "acpi_index");
227 /* SMBIOS type 41 — Onboard Devices Extended Information */
229 attr
= udev_device_get_sysattr_value(names
->pcidev
, "index");
233 idx
= strtoul(attr
, NULL
, 0);
237 /* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to report for
238 * example). Let's define a cut-off where we don't consider the index reliable anymore. We pick some arbitrary
239 * cut-off, which is somewhere beyond the realistic number of physical network interface a system might
240 * have. Ideally the kernel would already filter his crap for us, but it doesn't currently. */
241 if (idx
> ONBOARD_INDEX_MAX
)
244 /* kernel provided port index for multiple ports on a single PCI function */
245 attr
= udev_device_get_sysattr_value(dev
, "dev_port");
247 dev_port
= strtol(attr
, NULL
, 10);
249 /* kernel provided front panel port name for multiple port PCI device */
250 port_name
= udev_device_get_sysattr_value(dev
, "phys_port_name");
252 s
= names
->pci_onboard
;
253 l
= sizeof(names
->pci_onboard
);
254 l
= strpcpyf(&s
, l
, "o%d", idx
);
256 l
= strpcpyf(&s
, l
, "n%s", port_name
);
257 else if (dev_port
> 0)
258 l
= strpcpyf(&s
, l
, "d%d", dev_port
);
260 names
->pci_onboard
[0] = '\0';
262 names
->pci_onboard_label
= udev_device_get_sysattr_value(names
->pcidev
, "label");
267 /* read the 256 bytes PCI configuration space to check the multi-function bit */
268 static bool is_pci_multifunction(struct udev_device
*dev
) {
269 _cleanup_close_
int fd
= -1;
270 const char *filename
;
273 filename
= strjoina(udev_device_get_syspath(dev
), "/config");
274 fd
= open(filename
, O_RDONLY
| O_CLOEXEC
);
277 if (read(fd
, &config
, sizeof(config
)) != sizeof(config
))
280 /* bit 0-6 header type, bit 7 multi/single function device */
281 if ((config
[PCI_HEADER_TYPE
] & 0x80) != 0)
287 static bool is_pci_ari_enabled(struct udev_device
*dev
) {
288 return streq_ptr(udev_device_get_sysattr_value(dev
, "ari_enabled"), "1");
291 static int dev_pci_slot(struct udev_device
*dev
, struct netnames
*names
) {
292 struct udev
*udev
= udev_device_get_udev(names
->pcidev
);
293 unsigned domain
, bus
, slot
, func
, dev_port
= 0, hotplug_slot
= 0;
296 const char *attr
, *port_name
;
297 _cleanup_(udev_device_unrefp
) struct udev_device
*pci
= NULL
;
298 struct udev_device
*hotplug_slot_dev
;
299 char slots
[PATH_MAX
];
300 _cleanup_closedir_
DIR *dir
= NULL
;
303 if (sscanf(udev_device_get_sysname(names
->pcidev
), "%x:%x:%x.%u", &domain
, &bus
, &slot
, &func
) != 4)
305 if (is_pci_ari_enabled(names
->pcidev
))
306 /* ARI devices support up to 256 functions on a single device ("slot"), and interpret the
307 * traditional 5-bit slot and 3-bit function number as a single 8-bit function number,
308 * where the slot makes up the upper 5 bits. */
311 /* kernel provided port index for multiple ports on a single PCI function */
312 attr
= udev_device_get_sysattr_value(dev
, "dev_port");
314 dev_port
= strtol(attr
, NULL
, 10);
316 /* kernel provided front panel port name for multiple port PCI device */
317 port_name
= udev_device_get_sysattr_value(dev
, "phys_port_name");
319 /* compose a name based on the raw kernel's PCI bus, slot numbers */
321 l
= sizeof(names
->pci_path
);
323 l
= strpcpyf(&s
, l
, "P%u", domain
);
324 l
= strpcpyf(&s
, l
, "p%us%u", bus
, slot
);
325 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
326 l
= strpcpyf(&s
, l
, "f%u", func
);
328 l
= strpcpyf(&s
, l
, "n%s", port_name
);
329 else if (dev_port
> 0)
330 l
= strpcpyf(&s
, l
, "d%u", dev_port
);
332 names
->pci_path
[0] = '\0';
334 /* ACPI _SUN — slot user number */
335 pci
= udev_device_new_from_subsystem_sysname(udev
, "subsystem", "pci");
339 if (!snprintf_ok(slots
, sizeof slots
, "%s/slots", udev_device_get_syspath(pci
)))
340 return -ENAMETOOLONG
;
342 dir
= opendir(slots
);
346 hotplug_slot_dev
= names
->pcidev
;
347 while (hotplug_slot_dev
) {
348 FOREACH_DIRENT_ALL(dent
, dir
, break) {
352 _cleanup_free_
char *address
= NULL
;
354 if (dent
->d_name
[0] == '.')
356 r
= safe_atou_full(dent
->d_name
, 10, &i
);
360 if (snprintf_ok(str
, sizeof str
, "%s/%s/address", slots
, dent
->d_name
) &&
361 read_one_line_file(str
, &address
) >= 0)
362 /* match slot address with device by stripping the function */
363 if (startswith(udev_device_get_sysname(hotplug_slot_dev
), address
))
366 if (hotplug_slot
> 0)
369 if (hotplug_slot
> 0)
372 hotplug_slot_dev
= udev_device_get_parent_with_subsystem_devtype(hotplug_slot_dev
, "pci", NULL
);
375 if (hotplug_slot
> 0) {
377 l
= sizeof(names
->pci_slot
);
379 l
= strpcpyf(&s
, l
, "P%d", domain
);
380 l
= strpcpyf(&s
, l
, "s%d", hotplug_slot
);
381 if (func
> 0 || is_pci_multifunction(names
->pcidev
))
382 l
= strpcpyf(&s
, l
, "f%d", func
);
384 l
= strpcpyf(&s
, l
, "n%s", port_name
);
385 else if (dev_port
> 0)
386 l
= strpcpyf(&s
, l
, "d%d", dev_port
);
388 names
->pci_slot
[0] = '\0';
394 static int names_vio(struct udev_device
*dev
, struct netnames
*names
) {
395 struct udev_device
*parent
;
396 unsigned busid
, slotid
, ethid
;
399 /* check if our direct parent is a VIO device with no other bus in-between */
400 parent
= udev_device_get_parent(dev
);
404 if (!streq_ptr("vio", udev_device_get_subsystem(parent
)))
407 /* The devices' $DEVPATH number is tied to (virtual) hardware (slot id
408 * selected in the HMC), thus this provides a reliable naming (e.g.
409 * "/devices/vio/30000002/net/eth1"); we ignore the bus number, as
410 * there should only ever be one bus, and then remove leading zeros. */
411 syspath
= udev_device_get_syspath(dev
);
413 if (sscanf(syspath
, "/sys/devices/vio/%4x%4x/net/eth%u", &busid
, &slotid
, ðid
) != 3)
416 xsprintf(names
->vio_slot
, "v%u", slotid
);
417 names
->type
= NET_VIO
;
421 #define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
422 #define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
423 #define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
425 static int names_platform(struct udev_device
*dev
, struct netnames
*names
, bool test
) {
426 struct udev_device
*parent
;
428 unsigned model
, instance
, ethid
;
429 const char *syspath
, *pattern
, *validchars
;
431 /* check if our direct parent is a platform device with no other bus in-between */
432 parent
= udev_device_get_parent(dev
);
436 if (!streq_ptr("platform", udev_device_get_subsystem(parent
)))
439 syspath
= udev_device_get_syspath(dev
);
441 /* syspath is too short, to have a valid ACPI instance */
442 if (strlen(syspath
) < sizeof _PLATFORM_TEST
)
445 /* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
446 if (syspath
[sizeof _PLATFORM_TEST
- 1] == ':') {
447 pattern
= _PLATFORM_PATTERN4
;
448 validchars
= UPPERCASE_LETTERS DIGITS
;
450 pattern
= _PLATFORM_PATTERN3
;
451 validchars
= UPPERCASE_LETTERS
;
454 /* Platform devices are named after ACPI table match, and instance id
455 * eg. "/sys/devices/platform/HISI00C2:00");
456 * The Vendor (3 or 4 char), followed by hexdecimal model number : instance id.
459 #pragma GCC diagnostic push
460 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
461 if (sscanf(syspath
, pattern
, vendor
, &model
, &instance
, ðid
) != 4)
463 #pragma GCC diagnostic pop
465 if (!in_charset(vendor
, validchars
))
468 ascii_strlower(vendor
);
470 xsprintf(names
->platform_path
, "a%s%xi%u", vendor
, model
, instance
);
471 names
->type
= NET_PLATFORM
;
475 static int names_pci(struct udev_device
*dev
, struct netnames
*names
) {
476 struct udev_device
*parent
;
477 struct netnames vf_names
= {};
478 struct virtfn_info vf_info
= {};
483 parent
= udev_device_get_parent(dev
);
484 /* skip virtio subsystem if present */
485 parent
= skip_virtio(parent
);
490 /* check if our direct parent is a PCI device with no other bus in-between */
491 if (streq_ptr("pci", udev_device_get_subsystem(parent
))) {
492 names
->type
= NET_PCI
;
493 names
->pcidev
= parent
;
495 names
->pcidev
= udev_device_get_parent_with_subsystem_devtype(dev
, "pci", NULL
);
500 if (get_virtfn_info(dev
, names
, &vf_info
) >= 0) {
501 /* If this is an SR-IOV virtual device, get base name using physical device and add virtfn suffix. */
502 vf_names
.pcidev
= vf_info
.physfn_pcidev
;
503 dev_pci_onboard(dev
, &vf_names
);
504 dev_pci_slot(dev
, &vf_names
);
505 if (vf_names
.pci_onboard
[0])
506 if (strlen(vf_names
.pci_onboard
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_onboard
))
507 strscpyl(names
->pci_onboard
, sizeof(names
->pci_onboard
),
508 vf_names
.pci_onboard
, vf_info
.suffix
, NULL
);
509 if (vf_names
.pci_slot
[0])
510 if (strlen(vf_names
.pci_slot
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_slot
))
511 strscpyl(names
->pci_slot
, sizeof(names
->pci_slot
),
512 vf_names
.pci_slot
, vf_info
.suffix
, NULL
);
513 if (vf_names
.pci_path
[0])
514 if (strlen(vf_names
.pci_path
) + strlen(vf_info
.suffix
) < sizeof(names
->pci_path
))
515 strscpyl(names
->pci_path
, sizeof(names
->pci_path
),
516 vf_names
.pci_path
, vf_info
.suffix
, NULL
);
517 udev_device_unref(vf_info
.physfn_pcidev
);
519 dev_pci_onboard(dev
, names
);
520 dev_pci_slot(dev
, names
);
525 static int names_usb(struct udev_device
*dev
, struct netnames
*names
) {
526 struct udev_device
*usbdev
;
537 usbdev
= udev_device_get_parent_with_subsystem_devtype(dev
, "usb", "usb_interface");
541 /* get USB port number chain, configuration, interface */
542 strscpy(name
, sizeof(name
), udev_device_get_sysname(usbdev
));
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(struct udev_device
*dev
, struct netnames
*names
) {
582 struct udev_device
*bcmadev
;
588 bcmadev
= udev_device_get_parent_with_subsystem_devtype(dev
, "bcma", NULL
);
592 /* bus num:core num */
593 if (sscanf(udev_device_get_sysname(bcmadev
), "bcma%*u:%u", &core
) != 1)
595 /* suppress the common core == 0 */
597 xsprintf(names
->bcma_core
, "b%u", core
);
599 names
->type
= NET_BCMA
;
603 static int names_ccw(struct udev_device
*dev
, struct netnames
*names
) {
604 struct udev_device
*cdev
;
605 const char *bus_id
, *subsys
;
612 /* Retrieve the associated CCW device */
613 cdev
= udev_device_get_parent(dev
);
614 /* skip virtio subsystem if present */
615 cdev
= skip_virtio(cdev
);
619 /* Network devices are either single or grouped CCW devices */
620 subsys
= udev_device_get_subsystem(cdev
);
621 if (!STRPTR_IN_SET(subsys
, "ccwgroup", "ccw"))
624 /* Retrieve bus-ID of the CCW device. The bus-ID uniquely
625 * identifies the network device on the Linux on System z channel
626 * subsystem. Note that the bus-ID contains lowercase characters.
628 bus_id
= udev_device_get_sysname(cdev
);
632 /* Check the length of the bus-ID. Rely on that the kernel provides
633 * a correct bus-ID; alternatively, improve this check and parse and
634 * verify each bus-ID part...
636 bus_id_len
= strlen(bus_id
);
637 if (!IN_SET(bus_id_len
, 8, 9))
640 /* Strip leading zeros from the bus id for aesthetic purposes. This
641 * keeps the ccw names stable, yet much shorter in general case of
642 * bus_id 0.0.0600 -> 600. This is similar to e.g. how PCI domain is
643 * not prepended when it is zero. Preserve the last 0 for 0.0.0000.
645 bus_id_start
= strspn(bus_id
, ".0");
646 bus_id
+= bus_id_start
< bus_id_len
? bus_id_start
: bus_id_len
- 1;
648 /* Store the CCW bus-ID for use as network device name */
649 if (snprintf_ok(names
->ccw_busid
, sizeof(names
->ccw_busid
), "c%s", bus_id
))
650 names
->type
= NET_CCW
;
655 static int names_mac(struct udev_device
*dev
, struct netnames
*names
) {
658 unsigned int a1
, a2
, a3
, a4
, a5
, a6
;
660 /* check for NET_ADDR_PERM, skip random MAC addresses */
661 s
= udev_device_get_sysattr_value(dev
, "addr_assign_type");
664 i
= strtoul(s
, NULL
, 0);
668 s
= udev_device_get_sysattr_value(dev
, "address");
671 if (sscanf(s
, "%x:%x:%x:%x:%x:%x", &a1
, &a2
, &a3
, &a4
, &a5
, &a6
) != 6)
674 /* skip empty MAC addresses */
675 if (a1
+ a2
+ a3
+ a4
+ a5
+ a6
== 0)
684 names
->mac_valid
= true;
688 /* IEEE Organizationally Unique Identifier vendor string */
689 static int ieee_oui(struct udev_device
*dev
, struct netnames
*names
, bool test
) {
692 if (!names
->mac_valid
)
694 /* skip commonly misused 00:00:00 (Xerox) prefix */
695 if (memcmp(names
->mac
, "\0\0\0", 3) == 0)
697 xsprintf(str
, "OUI:%02X%02X%02X%02X%02X%02X", names
->mac
[0],
698 names
->mac
[1], names
->mac
[2], names
->mac
[3], names
->mac
[4],
700 udev_builtin_hwdb_lookup(dev
, NULL
, str
, NULL
, test
);
704 static int builtin_net_id(struct udev_device
*dev
, int argc
, char *argv
[], bool test
) {
709 const char *prefix
= "en";
710 struct netnames names
= {};
713 /* handle only ARPHRD_ETHER and ARPHRD_SLIP devices */
714 s
= udev_device_get_sysattr_value(dev
, "type");
717 i
= strtoul(s
, NULL
, 0);
729 /* skip stacked devices, like VLANs, ... */
730 s
= udev_device_get_sysattr_value(dev
, "ifindex");
733 p
= udev_device_get_sysattr_value(dev
, "iflink");
739 devtype
= udev_device_get_devtype(dev
);
741 if (streq("wlan", devtype
))
743 else if (streq("wwan", devtype
))
747 err
= names_mac(dev
, &names
);
748 if (err
>= 0 && names
.mac_valid
) {
751 xsprintf(str
, "%sx%02x%02x%02x%02x%02x%02x", prefix
,
752 names
.mac
[0], names
.mac
[1], names
.mac
[2],
753 names
.mac
[3], names
.mac
[4], names
.mac
[5]);
754 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_MAC", str
);
756 ieee_oui(dev
, &names
, test
);
759 /* get path names for Linux on System z network devices */
760 err
= names_ccw(dev
, &names
);
761 if (err
>= 0 && names
.type
== NET_CCW
) {
764 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.ccw_busid
))
765 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
769 /* get ibmveth/ibmvnic slot-based names. */
770 err
= names_vio(dev
, &names
);
771 if (err
>= 0 && names
.type
== NET_VIO
) {
774 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.vio_slot
))
775 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
779 /* get ACPI path names for ARM64 platform devices */
780 err
= names_platform(dev
, &names
, test
);
781 if (err
>= 0 && names
.type
== NET_PLATFORM
) {
784 if (snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.platform_path
))
785 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
789 /* get PCI based path names, we compose only PCI based paths */
790 err
= names_pci(dev
, &names
);
794 /* plain PCI device */
795 if (names
.type
== NET_PCI
) {
798 if (names
.pci_onboard
[0] &&
799 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_onboard
))
800 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_ONBOARD", str
);
802 if (names
.pci_onboard_label
&&
803 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_onboard_label
))
804 udev_builtin_add_property(dev
, test
, "ID_NET_LABEL_ONBOARD", str
);
806 if (names
.pci_path
[0] &&
807 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_path
))
808 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
810 if (names
.pci_slot
[0] &&
811 snprintf_ok(str
, sizeof str
, "%s%s", prefix
, names
.pci_slot
))
812 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
817 err
= names_usb(dev
, &names
);
818 if (err
>= 0 && names
.type
== NET_USB
) {
821 if (names
.pci_path
[0] &&
822 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.usb_ports
))
823 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
825 if (names
.pci_slot
[0] &&
826 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.usb_ports
))
827 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
832 err
= names_bcma(dev
, &names
);
833 if (err
>= 0 && names
.type
== NET_BCMA
) {
836 if (names
.pci_path
[0] &&
837 snprintf_ok(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_path
, names
.bcma_core
))
838 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_PATH", str
);
840 if (names
.pci_slot
[0] &&
841 snprintf(str
, sizeof str
, "%s%s%s", prefix
, names
.pci_slot
, names
.bcma_core
))
842 udev_builtin_add_property(dev
, test
, "ID_NET_NAME_SLOT", str
);
849 const struct udev_builtin udev_builtin_net_id
= {
851 .cmd
= builtin_net_id
,
852 .help
= "Network device properties",