summaryrefslogtreecommitdiff
path: root/src/udev/udev-builtin-net_id.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udev/udev-builtin-net_id.c')
-rw-r--r--src/udev/udev-builtin-net_id.c101
1 files changed, 12 insertions, 89 deletions
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 2c7dcf7d2a..c487bc00df 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -9,86 +9,7 @@
*
* http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames
*
- * Two character prefixes based on the type of interface:
- * en — Ethernet
- * ib — InfiniBand
- * sl — serial line IP (slip)
- * wl — wlan
- * ww — wwan
- *
- * Type of names:
- * b<number> — BCMA bus core number
- * c<bus_id> — bus id of a grouped CCW or CCW device,
- * with all leading zeros stripped [s390]
- * o<index>[n<phys_port_name>|d<dev_port>]
- * — on-board device index number
- * s<slot>[f<function>][n<phys_port_name>|d<dev_port>]
- * — hotplug slot index number
- * x<MAC> — MAC address
- * [P<domain>]p<bus>s<slot>[f<function>][n<phys_port_name>|d<dev_port>]
- * — PCI geographical location
- * [P<domain>]p<bus>s<slot>[f<function>][u<port>][..][c<config>][i<interface>]
- * — USB port number chain
- * v<slot> - VIO slot number (IBM PowerVM)
- * a<vendor><model>i<instance> — Platform bus ACPI instance id
- * i<addr>n<phys_port_name> — Netdevsim bus address and port name
- *
- * All multi-function PCI devices will carry the [f<function>] number in the
- * device name, including the function 0 device.
- *
- * SR-IOV virtual devices are named based on the name of the parent interface,
- * with a suffix of "v<N>", where <N> is the virtual device number.
- *
- * When using PCI geography, The PCI domain is only prepended when it is not 0.
- *
- * For USB devices the full chain of port numbers of hubs is composed. If the
- * name gets longer than the maximum number of 15 characters, the name is not
- * exported.
- * The usual USB configuration == 1 and interface == 0 values are suppressed.
- *
- * PCI Ethernet card with firmware index "1":
- * ID_NET_NAME_ONBOARD=eno1
- * ID_NET_NAME_ONBOARD_LABEL=Ethernet Port 1
- *
- * PCI Ethernet card in hotplug slot with firmware index number:
- * /sys/devices/pci0000:00/0000:00:1c.3/0000:05:00.0/net/ens1
- * ID_NET_NAME_MAC=enx000000000466
- * ID_NET_NAME_PATH=enp5s0
- * ID_NET_NAME_SLOT=ens1
- *
- * PCI Ethernet multi-function card with 2 ports:
- * /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.0/net/enp2s0f0
- * ID_NET_NAME_MAC=enx78e7d1ea46da
- * ID_NET_NAME_PATH=enp2s0f0
- * /sys/devices/pci0000:00/0000:00:1c.0/0000:02:00.1/net/enp2s0f1
- * ID_NET_NAME_MAC=enx78e7d1ea46dc
- * ID_NET_NAME_PATH=enp2s0f1
- *
- * PCI wlan card:
- * /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/net/wlp3s0
- * ID_NET_NAME_MAC=wlx0024d7e31130
- * ID_NET_NAME_PATH=wlp3s0
- *
- * PCI IB host adapter with 2 ports:
- * /sys/devices/pci0000:00/0000:00:03.0/0000:15:00.0/net/ibp21s0f0
- * ID_NET_NAME_PATH=ibp21s0f0
- * /sys/devices/pci0000:00/0000:00:03.0/0000:15:00.1/net/ibp21s0f1
- * ID_NET_NAME_PATH=ibp21s0f1
- *
- * USB built-in 3G modem:
- * /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.6/net/wwp0s29u1u4i6
- * ID_NET_NAME_MAC=wwx028037ec0200
- * ID_NET_NAME_PATH=wwp0s29u1u4i6
- *
- * USB Android phone:
- * /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/net/enp0s29u1u2
- * ID_NET_NAME_MAC=enxd626b3450fb5
- * ID_NET_NAME_PATH=enp0s29u1u2
- *
- * s390 grouped CCW interface:
- * /sys/devices/css0/0.0.0007/0.0.f5f0/group_device/net/encf5f0
- * ID_NET_NAME_MAC=enx026d3c00000a
- * ID_NET_NAME_PATH=encf5f0
+ * When the code here is changed, man/systemd.net-naming-scheme.xml must be updated too.
*/
#include <errno.h>
@@ -249,7 +170,7 @@ static int dev_pci_onboard(sd_device *dev, struct netnames *names) {
char *s;
int r;
- /* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
+ /* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
if (sd_device_get_sysattr_value(names->pcidev, "acpi_index", &attr) < 0) {
/* SMBIOS type 41 — Onboard Devices Extended Information */
r = sd_device_get_sysattr_value(names->pcidev, "index", &attr);
@@ -263,10 +184,11 @@ static int dev_pci_onboard(sd_device *dev, struct netnames *names) {
if (idx == 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX))
return -EINVAL;
- /* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to report for
- * example). Let's define a cut-off where we don't consider the index reliable anymore. We pick some arbitrary
- * cut-off, which is somewhere beyond the realistic number of physical network interface a system might
- * have. Ideally the kernel would already filter his crap for us, but it doesn't currently. */
+ /* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to
+ * report for example). Let's define a cut-off where we don't consider the index reliable anymore. We
+ * pick some arbitrary cut-off, which is somewhere beyond the realistic number of physical network
+ * interface a system might have. Ideally the kernel would already filter his crap for us, but it
+ * doesn't currently. */
if (idx > ONBOARD_INDEX_MAX)
return -ENOENT;
@@ -722,9 +644,8 @@ static int names_ccw(sd_device *dev, struct netnames *names) {
if (r < 0)
return r;
- /* Check the length of the bus-ID. Rely on that the kernel provides
- * a correct bus-ID; alternatively, improve this check and parse and
- * verify each bus-ID part...
+ /* Check the length of the bus-ID. Rely on the fact that the kernel provides a correct bus-ID;
+ * alternatively, improve this check and parse and verify each bus-ID part...
*/
bus_id_len = strlen(bus_id);
if (!IN_SET(bus_id_len, 8, 9))
@@ -960,7 +881,9 @@ static int builtin_net_id(sd_device *dev, int argc, char *argv[], bool test) {
udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
if (names.pci_onboard_label &&
- snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard_label))
+ snprintf_ok(str, sizeof str, "%s%s",
+ naming_scheme_has(NAMING_LABEL_NOPREFIX) ? "" : prefix,
+ names.pci_onboard_label))
udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
if (names.pci_path[0] &&