udev-builtin-net_id.c revision de892aea1c486b59e04884268b612081d1660514
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2012 Kay Sievers <kay@vrfy.org>
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * en -- ethernet
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * o<index> -- on-board device index
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * s<slot>[f<function>] -- hotplug slot number
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * x<MAC> -- MAC address
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * p<bus>s<slot>[f<function>] -- PCI/physical location
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ID_NET_NAME_ONBOARD=eno1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ID_NET_NAME_SLOT=ens1
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering * ID_NET_NAME_SLOT=ens2f0
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ID_NET_NAME_SLOT=ens2f1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ID_NET_NAME_MAC=enxf0def180d479
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ID_NET_NAME_PATH=enp0s25
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * ID_NET_NAME_PATH=enp19s3f0
0dd25fb9f005d8ab7ac4bc10a609d00569f8c56aLennart Poettering * ID_NET_NAME_PATH=enp19s3f1
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/* retrieve on-board index number and label from firmware */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int dev_pci_onboard(struct udev_device *dev, struct udev_device *parent, const char *prefix, bool test) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* ACPI _DSM -- device specific method for naming a PCI or PCI Express device */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering index = udev_device_get_sysattr_value(parent, "acpi_index");
1716f6dcf54d4c181c2e2558e3d5414f54c8d9caLennart Poettering /* SMBIOS type 41 -- Onboard Devices Extended Information */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering index = udev_device_get_sysattr_value(parent, "index");
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering snprintf(s, sizeof(s), "%so%d", prefix, idx);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering err = udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", s);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering label = udev_device_get_sysattr_value(parent, "label");
623a4c97b9175f95c4b1c6fc34e36c56f1e4ddbfLennart Poettering err = udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", label);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic bool is_pci_singlefunction(struct udev_device *dev) {
goto out;
goto out;
single = true;
out:
fclose(f);
return single;
static int dev_pci_slot(struct udev_device *dev, struct udev_device *parent, const char *prefix, bool test) {
unsigned int bus;
unsigned int slot;
unsigned int func;
int hotplug_slot = 0;
int err = 0;
return -ENOENT;
if (err < 0)
return err;
if (!pci) {
goto out;
if (!dir) {
goto out;
char *rest;
char *address;
hotplug_slot = i;
if (hotplug_slot > 0)
if (hotplug_slot > 0) {
out:
return err;
return -ENOENT;
return EXIT_FAILURE;
return -ENOENT;
return -EINVAL;
return -EINVAL;
const char *devtype;
return EXIT_FAILURE;
if (devtype) {
return EXIT_SUCCESS;