2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2012-11-09 12:37:40 +01:00
|
|
|
|
2012-11-20 18:10:45 +01:00
|
|
|
/*
|
2012-12-06 21:25:39 +01:00
|
|
|
* Predictable network interface device names based on:
|
2012-12-02 02:00:57 +01:00
|
|
|
* - firmware/bios-provided index numbers for on-board devices
|
|
|
|
* - firmware-provided pci-express hotplug slot index number
|
|
|
|
* - physical/geographical location of the hardware
|
|
|
|
* - the interface's MAC address
|
|
|
|
*
|
2019-12-11 12:04:55 +01:00
|
|
|
* https://systemd.io/PREDICTABLE_INTERFACE_NAMES
|
2013-01-19 16:01:26 +01:00
|
|
|
*
|
2019-05-09 12:34:30 +02:00
|
|
|
* When the code here is changed, man/systemd.net-naming-scheme.xml must be updated too.
|
2012-11-20 18:10:45 +01:00
|
|
|
*/
|
|
|
|
|
2012-11-09 12:37:40 +01:00
|
|
|
#include <errno.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <fcntl.h>
|
2012-12-06 20:42:49 +01:00
|
|
|
#include <net/if.h>
|
2014-04-06 18:00:26 +02:00
|
|
|
#include <net/if_arp.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2019-12-17 03:01:35 +01:00
|
|
|
#include <linux/if.h>
|
2012-11-30 19:27:42 +01:00
|
|
|
#include <linux/pci_regs.h>
|
2012-11-09 12:37:40 +01:00
|
|
|
|
2018-08-29 09:12:22 +02:00
|
|
|
#include "alloc-util.h"
|
2016-12-09 10:04:30 +01:00
|
|
|
#include "dirent-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2013-02-14 12:26:13 +01:00
|
|
|
#include "fileio.h"
|
2018-01-17 20:31:55 +01:00
|
|
|
#include "fs-util.h"
|
2020-01-02 19:33:29 +01:00
|
|
|
#include "netif-naming-scheme.h"
|
2018-01-16 22:08:10 +01:00
|
|
|
#include "parse-util.h"
|
2018-12-10 17:10:19 +01:00
|
|
|
#include "proc-cmdline.h"
|
2016-01-12 15:34:20 +01:00
|
|
|
#include "stdio-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2018-08-29 09:12:22 +02:00
|
|
|
#include "strv.h"
|
|
|
|
#include "strxcpyx.h"
|
|
|
|
#include "udev-builtin.h"
|
2012-11-09 12:37:40 +01:00
|
|
|
|
2016-01-25 17:16:27 +01:00
|
|
|
#define ONBOARD_INDEX_MAX (16*1024-1)
|
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
enum netname_type{
|
|
|
|
NET_UNDEF,
|
|
|
|
NET_PCI,
|
|
|
|
NET_USB,
|
2013-01-17 02:09:49 +01:00
|
|
|
NET_BCMA,
|
2014-01-04 14:43:45 +01:00
|
|
|
NET_VIRTIO,
|
2017-02-17 16:18:01 +01:00
|
|
|
NET_CCW,
|
2017-03-31 16:32:09 +02:00
|
|
|
NET_VIO,
|
2017-05-17 15:28:35 +02:00
|
|
|
NET_PLATFORM,
|
2019-04-15 20:34:44 +02:00
|
|
|
NET_NETDEVSIM,
|
2012-12-06 20:42:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct netnames {
|
|
|
|
enum netname_type type;
|
|
|
|
|
|
|
|
uint8_t mac[6];
|
|
|
|
bool mac_valid;
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
sd_device *pcidev;
|
2019-12-17 03:01:35 +01:00
|
|
|
char pci_slot[ALTIFNAMSIZ];
|
|
|
|
char pci_path[ALTIFNAMSIZ];
|
|
|
|
char pci_onboard[ALTIFNAMSIZ];
|
2012-12-06 20:42:49 +01:00
|
|
|
const char *pci_onboard_label;
|
|
|
|
|
2019-12-17 03:01:35 +01:00
|
|
|
char usb_ports[ALTIFNAMSIZ];
|
|
|
|
char bcma_core[ALTIFNAMSIZ];
|
|
|
|
char ccw_busid[ALTIFNAMSIZ];
|
|
|
|
char vio_slot[ALTIFNAMSIZ];
|
|
|
|
char platform_path[ALTIFNAMSIZ];
|
|
|
|
char netdevsim_path[ALTIFNAMSIZ];
|
2012-12-06 20:42:49 +01:00
|
|
|
};
|
|
|
|
|
2018-01-17 20:31:55 +01:00
|
|
|
struct virtfn_info {
|
2018-10-13 18:04:29 +02:00
|
|
|
sd_device *physfn_pcidev;
|
2019-12-17 03:01:35 +01:00
|
|
|
char suffix[ALTIFNAMSIZ];
|
2018-01-17 20:31:55 +01:00
|
|
|
};
|
|
|
|
|
2017-02-17 16:18:01 +01:00
|
|
|
/* skip intermediate virtio devices */
|
2018-10-13 18:04:29 +02:00
|
|
|
static sd_device *skip_virtio(sd_device *dev) {
|
|
|
|
sd_device *parent;
|
2017-02-17 16:18:01 +01:00
|
|
|
|
|
|
|
/* there can only ever be one virtio bus per parent device, so we can
|
2018-10-13 18:04:29 +02:00
|
|
|
* safely ignore any virtio buses. see
|
|
|
|
* http://lists.linuxfoundation.org/pipermail/virtualization/2015-August/030331.html */
|
|
|
|
for (parent = dev; parent; ) {
|
|
|
|
const char *subsystem;
|
|
|
|
|
|
|
|
if (sd_device_get_subsystem(parent, &subsystem) < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!streq(subsystem, "virtio"))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (sd_device_get_parent(parent, &parent) < 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-02-17 16:18:01 +01:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int get_virtfn_info(sd_device *dev, struct netnames *names, struct virtfn_info *ret) {
|
|
|
|
_cleanup_(sd_device_unrefp) sd_device *physfn_pcidev = NULL;
|
|
|
|
const char *physfn_link_file, *syspath;
|
2018-01-17 20:31:55 +01:00
|
|
|
_cleanup_free_ char *physfn_pci_syspath = NULL;
|
|
|
|
_cleanup_free_ char *virtfn_pci_syspath = NULL;
|
|
|
|
struct dirent *dent;
|
|
|
|
_cleanup_closedir_ DIR *dir = NULL;
|
2019-12-17 03:01:35 +01:00
|
|
|
char suffix[ALTIFNAMSIZ];
|
2018-01-17 20:31:55 +01:00
|
|
|
int r;
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
assert(dev);
|
|
|
|
assert(names);
|
|
|
|
assert(ret);
|
|
|
|
|
|
|
|
r = sd_device_get_syspath(names->pcidev, &syspath);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2018-01-17 20:31:55 +01:00
|
|
|
/* Check if this is a virtual function. */
|
2018-10-13 18:04:29 +02:00
|
|
|
physfn_link_file = strjoina(syspath, "/physfn");
|
2019-10-24 10:33:20 +02:00
|
|
|
r = chase_symlinks(physfn_link_file, NULL, 0, &physfn_pci_syspath, NULL);
|
2018-01-17 20:31:55 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* Get physical function's pci device. */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_new_from_syspath(&physfn_pcidev, physfn_pci_syspath);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2018-01-17 20:31:55 +01:00
|
|
|
|
|
|
|
/* Find the virtual function number by finding the right virtfn link. */
|
|
|
|
dir = opendir(physfn_pci_syspath);
|
2018-10-13 18:04:29 +02:00
|
|
|
if (!dir)
|
|
|
|
return -errno;
|
|
|
|
|
2018-01-17 20:31:55 +01:00
|
|
|
FOREACH_DIRENT_ALL(dent, dir, break) {
|
|
|
|
_cleanup_free_ char *virtfn_link_file = NULL;
|
2018-10-13 18:04:29 +02:00
|
|
|
|
2018-01-17 20:31:55 +01:00
|
|
|
if (!startswith(dent->d_name, "virtfn"))
|
|
|
|
continue;
|
2018-10-13 18:04:29 +02:00
|
|
|
|
2019-06-20 20:07:01 +02:00
|
|
|
virtfn_link_file = path_join(physfn_pci_syspath, dent->d_name);
|
2018-10-13 18:04:29 +02:00
|
|
|
if (!virtfn_link_file)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-10-24 10:33:20 +02:00
|
|
|
if (chase_symlinks(virtfn_link_file, NULL, 0, &virtfn_pci_syspath, NULL) < 0)
|
2018-01-17 20:31:55 +01:00
|
|
|
continue;
|
2018-10-13 18:04:29 +02:00
|
|
|
|
|
|
|
if (streq(syspath, virtfn_pci_syspath)) {
|
|
|
|
if (!snprintf_ok(suffix, sizeof(suffix), "v%s", &dent->d_name[6]))
|
|
|
|
return -ENOENT;
|
|
|
|
|
2018-01-17 20:31:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-13 18:04:29 +02:00
|
|
|
if (isempty(suffix))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
ret->physfn_pcidev = TAKE_PTR(physfn_pcidev);
|
|
|
|
strncpy(ret->suffix, suffix, sizeof(ret->suffix));
|
2018-01-17 20:31:55 +01:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
return 0;
|
2018-01-17 20:31:55 +01:00
|
|
|
}
|
|
|
|
|
2012-11-26 14:07:16 +01:00
|
|
|
/* retrieve on-board index number and label from firmware */
|
2018-10-13 18:04:29 +02:00
|
|
|
static int dev_pci_onboard(sd_device *dev, struct netnames *names) {
|
2018-09-24 18:59:54 +02:00
|
|
|
unsigned long idx, dev_port = 0;
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *attr, *port_name = NULL;
|
2015-04-01 16:51:02 +02:00
|
|
|
size_t l;
|
|
|
|
char *s;
|
2018-09-28 22:32:35 +02:00
|
|
|
int r;
|
2012-11-09 12:37:40 +01:00
|
|
|
|
2019-05-09 12:35:20 +02:00
|
|
|
/* ACPI _DSM — device specific method for naming a PCI or PCI Express device */
|
2018-10-13 18:04:29 +02:00
|
|
|
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);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
}
|
2015-04-01 16:51:02 +02:00
|
|
|
|
2018-09-28 22:32:35 +02:00
|
|
|
r = safe_atolu(attr, &idx);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2018-12-10 17:10:19 +01:00
|
|
|
if (idx == 0 && !naming_scheme_has(NAMING_ZERO_ACPI_INDEX))
|
|
|
|
return -EINVAL;
|
2015-04-01 16:51:02 +02:00
|
|
|
|
2019-05-09 12:35:20 +02:00
|
|
|
/* 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
|
2020-08-27 04:52:48 +02:00
|
|
|
* interface a system might have. Ideally the kernel would already filter this crap for us, but it
|
2019-05-09 12:35:20 +02:00
|
|
|
* doesn't currently. */
|
2016-01-25 17:16:27 +01:00
|
|
|
if (idx > ONBOARD_INDEX_MAX)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2015-04-01 23:34:19 +02:00
|
|
|
/* kernel provided port index for multiple ports on a single PCI function */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_sysattr_value(dev, "dev_port", &attr) >= 0)
|
2018-09-18 12:01:46 +02:00
|
|
|
dev_port = strtoul(attr, NULL, 10);
|
2015-04-01 16:51:02 +02:00
|
|
|
|
2016-11-02 03:46:01 +01:00
|
|
|
/* kernel provided front panel port name for multiple port PCI device */
|
2018-10-13 18:04:29 +02:00
|
|
|
(void) sd_device_get_sysattr_value(dev, "phys_port_name", &port_name);
|
2016-11-02 03:46:01 +01:00
|
|
|
|
2015-04-01 16:51:02 +02:00
|
|
|
s = names->pci_onboard;
|
|
|
|
l = sizeof(names->pci_onboard);
|
2018-09-24 18:59:54 +02:00
|
|
|
l = strpcpyf(&s, l, "o%lu", idx);
|
2016-11-02 03:46:01 +01:00
|
|
|
if (port_name)
|
|
|
|
l = strpcpyf(&s, l, "n%s", port_name);
|
|
|
|
else if (dev_port > 0)
|
2018-09-24 18:59:54 +02:00
|
|
|
l = strpcpyf(&s, l, "d%lu", dev_port);
|
2015-04-01 16:51:02 +02:00
|
|
|
if (l == 0)
|
|
|
|
names->pci_onboard[0] = '\0';
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_sysattr_value(names->pcidev, "label", &names->pci_onboard_label) < 0)
|
|
|
|
names->pci_onboard_label = NULL;
|
2015-04-01 16:51:02 +02:00
|
|
|
|
2012-11-26 14:07:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2012-12-03 15:47:18 +01:00
|
|
|
/* read the 256 bytes PCI configuration space to check the multi-function bit */
|
2018-10-13 18:04:29 +02:00
|
|
|
static bool is_pci_multifunction(sd_device *dev) {
|
2015-05-22 20:30:01 +02:00
|
|
|
_cleanup_close_ int fd = -1;
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *filename, *syspath;
|
2014-08-12 01:43:23 +02:00
|
|
|
uint8_t config[64];
|
2012-11-30 19:27:42 +01:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_syspath(dev, &syspath) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = strjoina(syspath, "/config");
|
2015-05-22 20:30:01 +02:00
|
|
|
fd = open(filename, O_RDONLY | O_CLOEXEC);
|
|
|
|
if (fd < 0)
|
2014-08-12 01:43:23 +02:00
|
|
|
return false;
|
2015-05-22 20:30:01 +02:00
|
|
|
if (read(fd, &config, sizeof(config)) != sizeof(config))
|
2014-08-12 01:43:23 +02:00
|
|
|
return false;
|
2012-11-30 19:27:42 +01:00
|
|
|
|
|
|
|
/* bit 0-6 header type, bit 7 multi/single function device */
|
2018-10-13 18:04:29 +02:00
|
|
|
return config[PCI_HEADER_TYPE] & 0x80;
|
2012-11-30 19:27:42 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static bool is_pci_ari_enabled(sd_device *dev) {
|
|
|
|
const char *a;
|
|
|
|
|
|
|
|
if (sd_device_get_sysattr_value(dev, "ari_enabled", &a) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return streq(a, "1");
|
2018-01-18 21:14:56 +01:00
|
|
|
}
|
|
|
|
|
2020-10-19 11:10:31 +02:00
|
|
|
static bool is_pci_bridge(sd_device *dev) {
|
|
|
|
const char *v, *p;
|
|
|
|
|
|
|
|
if (sd_device_get_sysattr_value(dev, "modalias", &v) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!startswith(v, "pci:"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
p = strrchr(v, 's');
|
|
|
|
if (!p)
|
|
|
|
return false;
|
|
|
|
if (p[1] != 'c')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* PCI device subclass 04 corresponds to PCI bridge */
|
|
|
|
return strneq(p + 2, "04", 2);
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int dev_pci_slot(sd_device *dev, struct netnames *names) {
|
2018-09-24 18:59:54 +02:00
|
|
|
unsigned long dev_port = 0;
|
2020-10-19 10:56:11 +02:00
|
|
|
unsigned domain, bus, slot, func;
|
|
|
|
int hotplug_slot = -1;
|
2013-01-04 19:08:08 +01:00
|
|
|
size_t l;
|
|
|
|
char *s;
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *sysname, *attr, *port_name = NULL, *syspath;
|
|
|
|
_cleanup_(sd_device_unrefp) sd_device *pci = NULL;
|
|
|
|
sd_device *hotplug_slot_dev;
|
2016-11-03 03:02:46 +01:00
|
|
|
char slots[PATH_MAX];
|
2013-12-15 22:26:27 +01:00
|
|
|
_cleanup_closedir_ DIR *dir = NULL;
|
2012-11-26 14:07:16 +01:00
|
|
|
struct dirent *dent;
|
2018-10-13 18:04:29 +02:00
|
|
|
int r;
|
2012-11-26 14:07:16 +01:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_sysname(names->pcidev, &sysname);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (sscanf(sysname, "%x:%x:%x.%u", &domain, &bus, &slot, &func) != 4)
|
2012-11-26 14:07:16 +01:00
|
|
|
return -ENOENT;
|
2018-10-13 18:04:29 +02:00
|
|
|
|
2018-12-10 17:10:19 +01:00
|
|
|
if (naming_scheme_has(NAMING_NPAR_ARI) &&
|
|
|
|
is_pci_ari_enabled(names->pcidev))
|
2018-01-18 21:14:56 +01:00
|
|
|
/* ARI devices support up to 256 functions on a single device ("slot"), and interpret the
|
|
|
|
* traditional 5-bit slot and 3-bit function number as a single 8-bit function number,
|
|
|
|
* where the slot makes up the upper 5 bits. */
|
|
|
|
func += slot * 8;
|
2013-01-04 19:08:08 +01:00
|
|
|
|
2015-04-01 23:34:19 +02:00
|
|
|
/* kernel provided port index for multiple ports on a single PCI function */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_sysattr_value(dev, "dev_port", &attr) >= 0) {
|
2018-09-18 12:01:46 +02:00
|
|
|
dev_port = strtoul(attr, NULL, 10);
|
2018-09-18 11:47:20 +02:00
|
|
|
/* With older kernels IP-over-InfiniBand network interfaces sometimes erroneously
|
|
|
|
* provide the port number in the 'dev_id' sysfs attribute instead of 'dev_port',
|
|
|
|
* which thus stays initialized as 0. */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (dev_port == 0 &&
|
|
|
|
sd_device_get_sysattr_value(dev, "type", &attr) >= 0) {
|
|
|
|
unsigned long type;
|
|
|
|
|
|
|
|
type = strtoul(attr, NULL, 10);
|
|
|
|
if (type == ARPHRD_INFINIBAND &&
|
|
|
|
sd_device_get_sysattr_value(dev, "dev_id", &attr) >= 0)
|
|
|
|
dev_port = strtoul(attr, NULL, 16);
|
2018-09-18 11:47:20 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:08:08 +01:00
|
|
|
|
2019-01-04 21:46:54 +01:00
|
|
|
/* kernel provided front panel port name for multi-port PCI device */
|
2018-10-13 18:04:29 +02:00
|
|
|
(void) sd_device_get_sysattr_value(dev, "phys_port_name", &port_name);
|
2016-11-02 03:46:01 +01:00
|
|
|
|
2013-01-04 19:08:08 +01:00
|
|
|
/* compose a name based on the raw kernel's PCI bus, slot numbers */
|
|
|
|
s = names->pci_path;
|
2013-06-12 15:32:47 +02:00
|
|
|
l = sizeof(names->pci_path);
|
|
|
|
if (domain > 0)
|
2015-01-21 04:22:15 +01:00
|
|
|
l = strpcpyf(&s, l, "P%u", domain);
|
|
|
|
l = strpcpyf(&s, l, "p%us%u", bus, slot);
|
2013-01-04 19:08:08 +01:00
|
|
|
if (func > 0 || is_pci_multifunction(names->pcidev))
|
2015-01-21 04:22:15 +01:00
|
|
|
l = strpcpyf(&s, l, "f%u", func);
|
2016-11-02 03:46:01 +01:00
|
|
|
if (port_name)
|
|
|
|
l = strpcpyf(&s, l, "n%s", port_name);
|
|
|
|
else if (dev_port > 0)
|
2018-09-24 18:59:54 +02:00
|
|
|
l = strpcpyf(&s, l, "d%lu", dev_port);
|
2013-01-04 19:08:08 +01:00
|
|
|
if (l == 0)
|
|
|
|
names->pci_path[0] = '\0';
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2019-01-04 21:46:54 +01:00
|
|
|
/* ACPI _SUN — slot user number */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_new_from_subsystem_sysname(&pci, "subsystem", "pci");
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2016-11-03 03:02:46 +01:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_syspath(pci, &syspath);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
if (!snprintf_ok(slots, sizeof slots, "%s/slots", syspath))
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
2012-11-26 14:07:16 +01:00
|
|
|
dir = opendir(slots);
|
2018-02-23 11:09:13 +01:00
|
|
|
if (!dir)
|
|
|
|
return -errno;
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2018-01-16 22:08:10 +01:00
|
|
|
hotplug_slot_dev = names->pcidev;
|
|
|
|
while (hotplug_slot_dev) {
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_sysname(hotplug_slot_dev, &sysname) < 0)
|
|
|
|
continue;
|
|
|
|
|
2018-01-16 22:08:10 +01:00
|
|
|
FOREACH_DIRENT_ALL(dent, dir, break) {
|
2020-10-19 10:56:11 +02:00
|
|
|
int i;
|
2018-01-16 22:08:10 +01:00
|
|
|
char str[PATH_MAX];
|
|
|
|
_cleanup_free_ char *address = NULL;
|
|
|
|
|
2020-01-07 18:02:53 +01:00
|
|
|
if (dot_or_dot_dot(dent->d_name))
|
2018-01-16 22:08:10 +01:00
|
|
|
continue;
|
2020-01-07 18:02:53 +01:00
|
|
|
|
2020-10-19 10:56:11 +02:00
|
|
|
r = safe_atoi(dent->d_name, &i);
|
2018-10-13 18:04:29 +02:00
|
|
|
if (r < 0 || i <= 0)
|
2018-01-16 22:08:10 +01:00
|
|
|
continue;
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
/* match slot address with device by stripping the function */
|
2018-01-16 22:08:10 +01:00
|
|
|
if (snprintf_ok(str, sizeof str, "%s/%s/address", slots, dent->d_name) &&
|
2018-10-13 18:04:29 +02:00
|
|
|
read_one_line_file(str, &address) >= 0 &&
|
|
|
|
startswith(sysname, address)) {
|
|
|
|
hotplug_slot = i;
|
2020-10-19 11:10:31 +02:00
|
|
|
|
|
|
|
/* We found the match between PCI device and slot. However, we won't use the
|
|
|
|
* slot index if the device is a PCI bridge, because it can have other child
|
|
|
|
* devices that will try to claim the same index and that would create name
|
|
|
|
* collision. */
|
|
|
|
if (naming_scheme_has(NAMING_BRIDGE_NO_SLOT) && is_pci_bridge(hotplug_slot_dev))
|
|
|
|
hotplug_slot = 0;
|
|
|
|
|
2018-01-16 22:08:10 +01:00
|
|
|
break;
|
2018-10-13 18:04:29 +02:00
|
|
|
}
|
2018-01-16 22:08:10 +01:00
|
|
|
}
|
2020-10-19 11:10:31 +02:00
|
|
|
if (hotplug_slot >= 0)
|
2012-11-26 14:07:16 +01:00
|
|
|
break;
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_parent_with_subsystem_devtype(hotplug_slot_dev, "pci", NULL, &hotplug_slot_dev) < 0)
|
|
|
|
break;
|
2018-01-16 22:08:10 +01:00
|
|
|
rewinddir(dir);
|
2012-11-26 14:07:16 +01:00
|
|
|
}
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2012-11-26 14:07:16 +01:00
|
|
|
if (hotplug_slot > 0) {
|
2013-01-04 19:08:08 +01:00
|
|
|
s = names->pci_slot;
|
2013-06-12 15:32:47 +02:00
|
|
|
l = sizeof(names->pci_slot);
|
|
|
|
if (domain > 0)
|
|
|
|
l = strpcpyf(&s, l, "P%d", domain);
|
|
|
|
l = strpcpyf(&s, l, "s%d", hotplug_slot);
|
2013-01-04 19:08:08 +01:00
|
|
|
if (func > 0 || is_pci_multifunction(names->pcidev))
|
2013-01-09 19:06:46 +01:00
|
|
|
l = strpcpyf(&s, l, "f%d", func);
|
2016-11-02 03:46:01 +01:00
|
|
|
if (port_name)
|
|
|
|
l = strpcpyf(&s, l, "n%s", port_name);
|
|
|
|
else if (dev_port > 0)
|
2018-09-24 18:59:54 +02:00
|
|
|
l = strpcpyf(&s, l, "d%lu", dev_port);
|
2013-01-04 19:08:08 +01:00
|
|
|
if (l == 0)
|
2015-04-01 16:41:41 +02:00
|
|
|
names->pci_slot[0] = '\0';
|
2012-11-20 18:10:45 +01:00
|
|
|
}
|
2018-02-23 11:09:13 +01:00
|
|
|
|
|
|
|
return 0;
|
2012-11-26 14:07:16 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int names_vio(sd_device *dev, struct netnames *names) {
|
|
|
|
sd_device *parent;
|
2017-03-31 16:32:09 +02:00
|
|
|
unsigned busid, slotid, ethid;
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *syspath, *subsystem;
|
|
|
|
int r;
|
2017-03-31 16:32:09 +02:00
|
|
|
|
|
|
|
/* check if our direct parent is a VIO device with no other bus in-between */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_parent(dev, &parent);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2017-03-31 16:32:09 +02:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_subsystem(parent, &subsystem);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
if (!streq("vio", subsystem))
|
|
|
|
return -ENOENT;
|
2017-03-31 16:32:09 +02:00
|
|
|
|
|
|
|
/* The devices' $DEVPATH number is tied to (virtual) hardware (slot id
|
|
|
|
* selected in the HMC), thus this provides a reliable naming (e.g.
|
|
|
|
* "/devices/vio/30000002/net/eth1"); we ignore the bus number, as
|
|
|
|
* there should only ever be one bus, and then remove leading zeros. */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_syspath(dev, &syspath);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2017-03-31 16:32:09 +02:00
|
|
|
|
|
|
|
if (sscanf(syspath, "/sys/devices/vio/%4x%4x/net/eth%u", &busid, &slotid, ðid) != 3)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
xsprintf(names->vio_slot, "v%u", slotid);
|
|
|
|
names->type = NET_VIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-17 15:28:35 +02:00
|
|
|
#define _PLATFORM_TEST "/sys/devices/platform/vvvvPPPP"
|
|
|
|
#define _PLATFORM_PATTERN4 "/sys/devices/platform/%4s%4x:%2x/net/eth%u"
|
|
|
|
#define _PLATFORM_PATTERN3 "/sys/devices/platform/%3s%4x:%2x/net/eth%u"
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int names_platform(sd_device *dev, struct netnames *names, bool test) {
|
|
|
|
sd_device *parent;
|
2017-05-17 15:28:35 +02:00
|
|
|
char vendor[5];
|
|
|
|
unsigned model, instance, ethid;
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *syspath, *pattern, *validchars, *subsystem;
|
|
|
|
int r;
|
2017-05-17 15:28:35 +02:00
|
|
|
|
|
|
|
/* check if our direct parent is a platform device with no other bus in-between */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_parent(dev, &parent);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_device_get_subsystem(parent, &subsystem);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2017-05-17 15:28:35 +02:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
if (!streq("platform", subsystem))
|
2017-05-17 15:28:35 +02:00
|
|
|
return -ENOENT;
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_syspath(dev, &syspath);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2017-05-17 15:28:35 +02:00
|
|
|
|
|
|
|
/* syspath is too short, to have a valid ACPI instance */
|
|
|
|
if (strlen(syspath) < sizeof _PLATFORM_TEST)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Vendor ID can be either PNP ID (3 chars A-Z) or ACPI ID (4 chars A-Z and numerals) */
|
|
|
|
if (syspath[sizeof _PLATFORM_TEST - 1] == ':') {
|
|
|
|
pattern = _PLATFORM_PATTERN4;
|
|
|
|
validchars = UPPERCASE_LETTERS DIGITS;
|
|
|
|
} else {
|
|
|
|
pattern = _PLATFORM_PATTERN3;
|
|
|
|
validchars = UPPERCASE_LETTERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Platform devices are named after ACPI table match, and instance id
|
|
|
|
* eg. "/sys/devices/platform/HISI00C2:00");
|
2020-12-14 01:40:45 +01:00
|
|
|
* The Vendor (3 or 4 char), followed by hexadecimal model number : instance id. */
|
2017-05-18 18:25:02 +02:00
|
|
|
|
2020-05-25 18:16:33 +02:00
|
|
|
DISABLE_WARNING_FORMAT_NONLITERAL;
|
2017-05-17 15:28:35 +02:00
|
|
|
if (sscanf(syspath, pattern, vendor, &model, &instance, ðid) != 4)
|
|
|
|
return -EINVAL;
|
2020-05-25 18:16:33 +02:00
|
|
|
REENABLE_WARNING;
|
2017-05-17 15:28:35 +02:00
|
|
|
|
|
|
|
if (!in_charset(vendor, validchars))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
ascii_strlower(vendor);
|
|
|
|
|
|
|
|
xsprintf(names->platform_path, "a%s%xi%u", vendor, model, instance);
|
|
|
|
names->type = NET_PLATFORM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int names_pci(sd_device *dev, struct netnames *names) {
|
|
|
|
sd_device *parent;
|
2018-01-17 20:31:55 +01:00
|
|
|
struct netnames vf_names = {};
|
|
|
|
struct virtfn_info vf_info = {};
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *subsystem;
|
|
|
|
int r;
|
2012-11-26 14:07:16 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(dev);
|
|
|
|
assert(names);
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_parent(dev, &parent);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2017-02-17 16:18:01 +01:00
|
|
|
/* skip virtio subsystem if present */
|
|
|
|
parent = skip_virtio(parent);
|
2015-08-25 14:12:19 +02:00
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
if (!parent)
|
|
|
|
return -ENOENT;
|
2015-08-25 14:12:19 +02:00
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
/* check if our direct parent is a PCI device with no other bus in-between */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_subsystem(parent, &subsystem) >= 0 &&
|
|
|
|
streq("pci", subsystem)) {
|
2012-12-06 20:42:49 +01:00
|
|
|
names->type = NET_PCI;
|
|
|
|
names->pcidev = parent;
|
|
|
|
} else {
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_parent_with_subsystem_devtype(dev, "pci", NULL, &names->pcidev);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2012-12-06 20:42:49 +01:00
|
|
|
}
|
2018-01-17 20:31:55 +01:00
|
|
|
|
2018-12-10 17:10:19 +01:00
|
|
|
if (naming_scheme_has(NAMING_SR_IOV_V) &&
|
|
|
|
get_virtfn_info(dev, names, &vf_info) >= 0) {
|
2018-01-17 20:31:55 +01:00
|
|
|
/* If this is an SR-IOV virtual device, get base name using physical device and add virtfn suffix. */
|
|
|
|
vf_names.pcidev = vf_info.physfn_pcidev;
|
|
|
|
dev_pci_onboard(dev, &vf_names);
|
|
|
|
dev_pci_slot(dev, &vf_names);
|
|
|
|
if (vf_names.pci_onboard[0])
|
|
|
|
if (strlen(vf_names.pci_onboard) + strlen(vf_info.suffix) < sizeof(names->pci_onboard))
|
|
|
|
strscpyl(names->pci_onboard, sizeof(names->pci_onboard),
|
|
|
|
vf_names.pci_onboard, vf_info.suffix, NULL);
|
|
|
|
if (vf_names.pci_slot[0])
|
|
|
|
if (strlen(vf_names.pci_slot) + strlen(vf_info.suffix) < sizeof(names->pci_slot))
|
|
|
|
strscpyl(names->pci_slot, sizeof(names->pci_slot),
|
|
|
|
vf_names.pci_slot, vf_info.suffix, NULL);
|
|
|
|
if (vf_names.pci_path[0])
|
|
|
|
if (strlen(vf_names.pci_path) + strlen(vf_info.suffix) < sizeof(names->pci_path))
|
|
|
|
strscpyl(names->pci_path, sizeof(names->pci_path),
|
|
|
|
vf_names.pci_path, vf_info.suffix, NULL);
|
2018-10-13 18:04:29 +02:00
|
|
|
sd_device_unref(vf_info.physfn_pcidev);
|
2018-01-17 20:31:55 +01:00
|
|
|
} else {
|
|
|
|
dev_pci_onboard(dev, names);
|
|
|
|
dev_pci_slot(dev, names);
|
|
|
|
}
|
2018-10-13 18:04:29 +02:00
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int names_usb(sd_device *dev, struct netnames *names) {
|
|
|
|
sd_device *usbdev;
|
|
|
|
char name[256], *ports, *config, *interf, *s;
|
|
|
|
const char *sysname;
|
2012-12-06 20:42:49 +01:00
|
|
|
size_t l;
|
2018-10-13 18:04:29 +02:00
|
|
|
int r;
|
2012-12-06 20:42:49 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(dev);
|
|
|
|
assert(names);
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_interface", &usbdev);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_device_get_sysname(usbdev, &sysname);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2012-11-26 14:07:16 +01:00
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
/* get USB port number chain, configuration, interface */
|
2018-10-13 18:04:29 +02:00
|
|
|
strscpy(name, sizeof(name), sysname);
|
2012-12-06 20:42:49 +01:00
|
|
|
s = strchr(name, '-');
|
|
|
|
if (!s)
|
|
|
|
return -EINVAL;
|
|
|
|
ports = s+1;
|
|
|
|
|
|
|
|
s = strchr(ports, ':');
|
|
|
|
if (!s)
|
|
|
|
return -EINVAL;
|
|
|
|
s[0] = '\0';
|
|
|
|
config = s+1;
|
|
|
|
|
|
|
|
s = strchr(config, '.');
|
|
|
|
if (!s)
|
|
|
|
return -EINVAL;
|
|
|
|
s[0] = '\0';
|
|
|
|
interf = s+1;
|
|
|
|
|
2014-12-10 20:00:09 +01:00
|
|
|
/* prefix every port number in the chain with "u" */
|
2012-12-06 20:42:49 +01:00
|
|
|
s = ports;
|
|
|
|
while ((s = strchr(s, '.')))
|
|
|
|
s[0] = 'u';
|
|
|
|
s = names->usb_ports;
|
2013-01-09 19:06:46 +01:00
|
|
|
l = strpcpyl(&s, sizeof(names->usb_ports), "u", ports, NULL);
|
2012-12-06 20:42:49 +01:00
|
|
|
|
|
|
|
/* append USB config number, suppress the common config == 1 */
|
|
|
|
if (!streq(config, "1"))
|
2013-01-09 19:06:46 +01:00
|
|
|
l = strpcpyl(&s, sizeof(names->usb_ports), "c", config, NULL);
|
2012-12-06 20:42:49 +01:00
|
|
|
|
|
|
|
/* append USB interface number, suppress the interface == 0 */
|
|
|
|
if (!streq(interf, "0"))
|
2013-01-09 19:06:46 +01:00
|
|
|
l = strpcpyl(&s, sizeof(names->usb_ports), "i", interf, NULL);
|
2012-12-06 20:42:49 +01:00
|
|
|
if (l == 0)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
names->type = NET_USB;
|
2012-11-20 18:10:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int names_bcma(sd_device *dev, struct netnames *names) {
|
|
|
|
sd_device *bcmadev;
|
2018-10-19 20:00:46 +02:00
|
|
|
unsigned core;
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *sysname;
|
|
|
|
int r;
|
2013-01-17 02:09:49 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(dev);
|
|
|
|
assert(names);
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_parent_with_subsystem_devtype(dev, "bcma", NULL, &bcmadev);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = sd_device_get_sysname(bcmadev, &sysname);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2013-01-17 02:09:49 +01:00
|
|
|
|
2013-01-17 03:30:07 +01:00
|
|
|
/* bus num:core num */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sscanf(sysname, "bcma%*u:%u", &core) != 1)
|
2013-01-17 02:09:49 +01:00
|
|
|
return -EINVAL;
|
2013-01-17 03:30:07 +01:00
|
|
|
/* suppress the common core == 0 */
|
|
|
|
if (core > 0)
|
2016-01-12 15:34:20 +01:00
|
|
|
xsprintf(names->bcma_core, "b%u", core);
|
2013-01-17 03:30:07 +01:00
|
|
|
|
2013-01-17 02:09:49 +01:00
|
|
|
names->type = NET_BCMA;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int names_ccw(sd_device *dev, struct netnames *names) {
|
|
|
|
sd_device *cdev;
|
2017-02-19 09:00:42 +01:00
|
|
|
const char *bus_id, *subsys;
|
2014-01-09 11:28:12 +01:00
|
|
|
size_t bus_id_len;
|
2017-02-17 16:18:01 +01:00
|
|
|
size_t bus_id_start;
|
2018-10-13 18:04:29 +02:00
|
|
|
int r;
|
2014-01-09 11:28:12 +01:00
|
|
|
|
2015-06-02 16:52:07 +02:00
|
|
|
assert(dev);
|
|
|
|
assert(names);
|
|
|
|
|
2014-01-09 11:28:12 +01:00
|
|
|
/* Retrieve the associated CCW device */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_parent(dev, &cdev);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2017-02-17 16:18:01 +01:00
|
|
|
/* skip virtio subsystem if present */
|
|
|
|
cdev = skip_virtio(cdev);
|
2014-01-09 11:28:12 +01:00
|
|
|
if (!cdev)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_subsystem(cdev, &subsys);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2017-02-17 16:18:01 +01:00
|
|
|
/* Network devices are either single or grouped CCW devices */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (!STR_IN_SET(subsys, "ccwgroup", "ccw"))
|
2014-01-09 11:28:12 +01:00
|
|
|
return -ENOENT;
|
|
|
|
|
2017-02-17 16:18:01 +01:00
|
|
|
/* Retrieve bus-ID of the CCW device. The bus-ID uniquely
|
2014-01-09 11:28:12 +01:00
|
|
|
* identifies the network device on the Linux on System z channel
|
|
|
|
* subsystem. Note that the bus-ID contains lowercase characters.
|
|
|
|
*/
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_sysname(cdev, &bus_id);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-01-09 11:28:12 +01:00
|
|
|
|
2019-05-09 12:35:20 +02:00
|
|
|
/* 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...
|
2014-01-09 11:28:12 +01:00
|
|
|
*/
|
|
|
|
bus_id_len = strlen(bus_id);
|
2017-12-25 05:38:49 +01:00
|
|
|
if (!IN_SET(bus_id_len, 8, 9))
|
2014-01-09 11:28:12 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-01-29 17:54:30 +01:00
|
|
|
/* Strip leading zeros from the bus id for aesthetic purposes. This
|
|
|
|
* keeps the ccw names stable, yet much shorter in general case of
|
|
|
|
* bus_id 0.0.0600 -> 600. This is similar to e.g. how PCI domain is
|
2017-02-17 16:18:01 +01:00
|
|
|
* not prepended when it is zero. Preserve the last 0 for 0.0.0000.
|
2016-01-29 17:54:30 +01:00
|
|
|
*/
|
2017-02-17 16:18:01 +01:00
|
|
|
bus_id_start = strspn(bus_id, ".0");
|
|
|
|
bus_id += bus_id_start < bus_id_len ? bus_id_start : bus_id_len - 1;
|
2016-01-29 17:54:30 +01:00
|
|
|
|
2014-01-09 11:28:12 +01:00
|
|
|
/* Store the CCW bus-ID for use as network device name */
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (snprintf_ok(names->ccw_busid, sizeof(names->ccw_busid), "c%s", bus_id))
|
2017-02-17 16:18:01 +01:00
|
|
|
names->type = NET_CCW;
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
|
2014-01-09 11:28:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
static int names_mac(sd_device *dev, struct netnames *names) {
|
2012-11-20 18:10:45 +01:00
|
|
|
const char *s;
|
2018-09-24 18:59:54 +02:00
|
|
|
unsigned long i;
|
2018-10-19 20:00:46 +02:00
|
|
|
unsigned a1, a2, a3, a4, a5, a6;
|
2018-10-13 18:04:29 +02:00
|
|
|
int r;
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2018-08-29 03:20:43 +02:00
|
|
|
/* Some kinds of devices tend to have hardware addresses
|
|
|
|
* that are impossible to use in an iface name.
|
|
|
|
*/
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_sysattr_value(dev, "type", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2018-08-29 03:20:43 +02:00
|
|
|
i = strtoul(s, NULL, 0);
|
|
|
|
switch (i) {
|
|
|
|
/* The persistent part of a hardware address of an InfiniBand NIC
|
|
|
|
* is 8 bytes long. We cannot fit this much in an iface name.
|
|
|
|
*/
|
|
|
|
case ARPHRD_INFINIBAND:
|
|
|
|
return -EINVAL;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-20 18:10:45 +01:00
|
|
|
/* check for NET_ADDR_PERM, skip random MAC addresses */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_sysattr_value(dev, "addr_assign_type", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2012-11-20 18:10:45 +01:00
|
|
|
i = strtoul(s, NULL, 0);
|
|
|
|
if (i != 0)
|
|
|
|
return 0;
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_sysattr_value(dev, "address", &s);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2012-11-20 18:10:45 +01:00
|
|
|
if (sscanf(s, "%x:%x:%x:%x:%x:%x", &a1, &a2, &a3, &a4, &a5, &a6) != 6)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* skip empty MAC addresses */
|
|
|
|
if (a1 + a2 + a3 + a4 + a5 + a6 == 0)
|
2012-11-09 12:37:40 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
names->mac[0] = a1;
|
|
|
|
names->mac[1] = a2;
|
|
|
|
names->mac[2] = a3;
|
|
|
|
names->mac[3] = a4;
|
|
|
|
names->mac[4] = a5;
|
|
|
|
names->mac[5] = a6;
|
|
|
|
names->mac_valid = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2019-04-15 20:34:44 +02:00
|
|
|
static int names_netdevsim(sd_device *dev, struct netnames *names) {
|
|
|
|
sd_device *netdevsimdev;
|
|
|
|
const char *sysname;
|
|
|
|
unsigned addr;
|
|
|
|
const char *port_name = NULL;
|
|
|
|
int r;
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
if (!naming_scheme_has(NAMING_NETDEVSIM))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
assert(dev);
|
|
|
|
assert(names);
|
|
|
|
|
|
|
|
r = sd_device_get_parent_with_subsystem_devtype(dev, "netdevsim", NULL, &netdevsimdev);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
r = sd_device_get_sysname(netdevsimdev, &sysname);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (sscanf(sysname, "netdevsim%u", &addr) != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
r = sd_device_get_sysattr_value(dev, "phys_port_name", &port_name);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
ok = snprintf_ok(names->netdevsim_path, sizeof(names->netdevsim_path), "i%un%s", addr, port_name);
|
|
|
|
if (!ok)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
|
|
|
names->type = NET_NETDEVSIM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
/* IEEE Organizationally Unique Identifier vendor string */
|
2018-10-13 18:04:29 +02:00
|
|
|
static int ieee_oui(sd_device *dev, struct netnames *names, bool test) {
|
2012-12-06 21:37:10 +01:00
|
|
|
char str[32];
|
2012-12-06 20:42:49 +01:00
|
|
|
|
2012-12-06 21:37:10 +01:00
|
|
|
if (!names->mac_valid)
|
2012-12-06 20:42:49 +01:00
|
|
|
return -ENOENT;
|
|
|
|
/* skip commonly misused 00:00:00 (Xerox) prefix */
|
|
|
|
if (memcmp(names->mac, "\0\0\0", 3) == 0)
|
|
|
|
return -EINVAL;
|
2016-01-12 15:34:20 +01:00
|
|
|
xsprintf(str, "OUI:%02X%02X%02X%02X%02X%02X", names->mac[0],
|
|
|
|
names->mac[1], names->mac[2], names->mac[3], names->mac[4],
|
|
|
|
names->mac[5]);
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_hwdb_lookup(dev, NULL, str, NULL, test);
|
2012-12-06 20:42:49 +01:00
|
|
|
return 0;
|
2012-11-09 12:37:40 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:22:14 +02:00
|
|
|
static int builtin_net_id(sd_device *dev, int argc, char *argv[], bool test) {
|
2018-10-13 18:04:29 +02:00
|
|
|
const char *s, *p, *devtype, *prefix = "en";
|
2013-03-25 00:59:00 +01:00
|
|
|
struct netnames names = {};
|
2018-10-13 18:04:29 +02:00
|
|
|
unsigned long i;
|
|
|
|
int r;
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
/* handle only ARPHRD_ETHER, ARPHRD_SLIP and ARPHRD_INFINIBAND devices */
|
|
|
|
r = sd_device_get_sysattr_value(dev, "type", &s);
|
|
|
|
if (r < 0)
|
2018-10-23 11:26:06 +02:00
|
|
|
return r;
|
2018-10-13 18:04:29 +02:00
|
|
|
|
2012-11-20 18:10:45 +01:00
|
|
|
i = strtoul(s, NULL, 0);
|
2014-01-09 11:28:12 +01:00
|
|
|
switch (i) {
|
2014-04-06 18:00:26 +02:00
|
|
|
case ARPHRD_ETHER:
|
2014-01-09 11:28:12 +01:00
|
|
|
prefix = "en";
|
|
|
|
break;
|
2018-08-29 03:07:55 +02:00
|
|
|
case ARPHRD_INFINIBAND:
|
2018-12-10 17:10:19 +01:00
|
|
|
if (naming_scheme_has(NAMING_INFINIBAND))
|
|
|
|
prefix = "ib";
|
|
|
|
else
|
|
|
|
return 0;
|
2018-08-29 03:07:55 +02:00
|
|
|
break;
|
2014-04-06 18:00:26 +02:00
|
|
|
case ARPHRD_SLIP:
|
2014-01-09 11:28:12 +01:00
|
|
|
prefix = "sl";
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-20 18:10:45 +01:00
|
|
|
return 0;
|
2014-01-09 11:28:12 +01:00
|
|
|
}
|
2012-11-20 18:10:45 +01:00
|
|
|
|
2013-01-08 14:54:12 +01:00
|
|
|
/* skip stacked devices, like VLANs, ... */
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_sysattr_value(dev, "ifindex", &s);
|
|
|
|
if (r < 0)
|
2018-10-23 11:26:06 +02:00
|
|
|
return r;
|
2018-10-13 18:04:29 +02:00
|
|
|
r = sd_device_get_sysattr_value(dev, "iflink", &p);
|
|
|
|
if (r < 0)
|
2018-10-23 11:26:06 +02:00
|
|
|
return r;
|
2013-02-13 18:13:22 +01:00
|
|
|
if (!streq(s, p))
|
2013-01-08 14:54:12 +01:00
|
|
|
return 0;
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
if (sd_device_get_devtype(dev, &devtype) >= 0) {
|
2012-11-20 18:10:45 +01:00
|
|
|
if (streq("wlan", devtype))
|
|
|
|
prefix = "wl";
|
|
|
|
else if (streq("wwan", devtype))
|
|
|
|
prefix = "ww";
|
|
|
|
}
|
|
|
|
|
2018-12-10 17:10:19 +01:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAMING_SCHEME", naming_scheme()->name);
|
|
|
|
|
2018-10-13 18:04:29 +02:00
|
|
|
r = names_mac(dev, &names);
|
|
|
|
if (r >= 0 && names.mac_valid) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2012-12-06 20:42:49 +01:00
|
|
|
|
2016-01-12 15:34:20 +01:00
|
|
|
xsprintf(str, "%sx%02x%02x%02x%02x%02x%02x", prefix,
|
2012-12-06 20:42:49 +01:00
|
|
|
names.mac[0], names.mac[1], names.mac[2],
|
|
|
|
names.mac[3], names.mac[4], names.mac[5]);
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_MAC", str);
|
2012-12-06 20:42:49 +01:00
|
|
|
|
|
|
|
ieee_oui(dev, &names, test);
|
|
|
|
}
|
|
|
|
|
2014-01-09 11:28:12 +01:00
|
|
|
/* get path names for Linux on System z network devices */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (names_ccw(dev, &names) >= 0 && names.type == NET_CCW) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2014-01-09 11:28:12 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.ccw_busid))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2014-01-09 11:28:12 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 16:32:09 +02:00
|
|
|
/* get ibmveth/ibmvnic slot-based names. */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (names_vio(dev, &names) >= 0 && names.type == NET_VIO) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2017-03-31 16:32:09 +02:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.vio_slot))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2017-03-31 16:32:09 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 15:28:35 +02:00
|
|
|
/* get ACPI path names for ARM64 platform devices */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (names_platform(dev, &names, test) >= 0 && names.type == NET_PLATFORM) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2017-05-17 15:28:35 +02:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.platform_path))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2017-05-17 15:28:35 +02:00
|
|
|
}
|
|
|
|
|
2019-04-15 20:34:44 +02:00
|
|
|
/* get netdevsim path names */
|
|
|
|
if (names_netdevsim(dev, &names) >= 0 && names.type == NET_NETDEVSIM) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2019-04-15 20:34:44 +02:00
|
|
|
|
|
|
|
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.netdevsim_path))
|
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 20:42:49 +01:00
|
|
|
/* get PCI based path names, we compose only PCI based paths */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (names_pci(dev, &names) < 0)
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2012-12-06 20:42:49 +01:00
|
|
|
|
|
|
|
/* plain PCI device */
|
|
|
|
if (names.type == NET_PCI) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2012-12-06 20:42:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_onboard[0] &&
|
|
|
|
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
|
2012-12-06 20:42:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_onboard_label &&
|
2019-05-09 12:41:52 +02:00
|
|
|
snprintf_ok(str, sizeof str, "%s%s",
|
|
|
|
naming_scheme_has(NAMING_LABEL_NOPREFIX) ? "" : prefix,
|
|
|
|
names.pci_onboard_label))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
|
2012-12-06 20:42:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_path[0] &&
|
|
|
|
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_path))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
|
2012-12-06 20:42:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_slot[0] &&
|
|
|
|
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_slot))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2012-12-06 20:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* USB device */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (names_usb(dev, &names) >= 0 && names.type == NET_USB) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2012-12-06 20:42:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_path[0] &&
|
|
|
|
snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.usb_ports))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
|
2012-12-06 20:42:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_slot[0] &&
|
|
|
|
snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.usb_ports))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2013-01-17 02:09:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Broadcom bus */
|
2018-10-13 18:04:29 +02:00
|
|
|
if (names_bcma(dev, &names) >= 0 && names.type == NET_BCMA) {
|
2019-12-17 03:01:35 +01:00
|
|
|
char str[ALTIFNAMSIZ];
|
2013-01-17 02:09:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_path[0] &&
|
|
|
|
snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.bcma_core))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
|
2013-01-17 02:09:49 +01:00
|
|
|
|
udev/net-id: check all snprintf return values
gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.
2018-02-23 11:12:19 +01:00
|
|
|
if (names.pci_slot[0] &&
|
|
|
|
snprintf(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.bcma_core))
|
2018-10-13 18:04:29 +02:00
|
|
|
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2012-12-06 20:42:49 +01:00
|
|
|
}
|
2018-10-13 18:04:29 +02:00
|
|
|
|
2018-10-23 11:26:06 +02:00
|
|
|
return 0;
|
2012-11-09 12:37:40 +01:00
|
|
|
}
|
|
|
|
|
2019-04-25 01:21:11 +02:00
|
|
|
const UdevBuiltin udev_builtin_net_id = {
|
2012-11-09 12:37:40 +01:00
|
|
|
.name = "net_id",
|
|
|
|
.cmd = builtin_net_id,
|
2015-01-05 13:19:55 +01:00
|
|
|
.help = "Network device properties",
|
2012-11-09 12:37:40 +01:00
|
|
|
};
|