diff --git a/src/udev/net/naming-scheme.c b/src/udev/net/naming-scheme.c index 27cede5e2e..8223f9cda1 100644 --- a/src/udev/net/naming-scheme.c +++ b/src/udev/net/naming-scheme.c @@ -8,6 +8,7 @@ static const NamingScheme naming_schemes[] = { { "v238", NAMING_V238 }, { "v239", NAMING_V239 }, { "v240", NAMING_V240 }, + { "v243", NAMING_V243 }, /* … add more schemes here, as the logic to name devices is updated … */ }; diff --git a/src/udev/net/naming-scheme.h b/src/udev/net/naming-scheme.h index 0b3d9bff1d..1f7cb0ccb9 100644 --- a/src/udev/net/naming-scheme.h +++ b/src/udev/net/naming-scheme.h @@ -27,11 +27,13 @@ typedef enum NamingSchemeFlags { NAMING_INFINIBAND = 1 << 2, /* Use "ib" prefix for infiniband, see 938d30aa98df887797c9e05074a562ddacdcdf5e */ NAMING_ZERO_ACPI_INDEX = 1 << 3, /* Allow zero acpi_index field, see d81186ef4f6a888a70f20a1e73a812d6acb9e22f */ NAMING_ALLOW_RERENAMES = 1 << 4, /* Allow re-renaming of devices, see #9006 */ + NAMING_NETDEVSIM = 1 << 5, /* Allow re-renaming of netdevsim devices */ /* And now the masks that combine the features above */ NAMING_V238 = 0, NAMING_V239 = NAMING_V238 | NAMING_SR_IOV_V | NAMING_NPAR_ARI, NAMING_V240 = NAMING_V239 | NAMING_INFINIBAND | NAMING_ZERO_ACPI_INDEX | NAMING_ALLOW_RERENAMES, + NAMING_V243 = NAMING_V240 | NAMING_NETDEVSIM, _NAMING_SCHEME_FLAGS_INVALID = -1, } NamingSchemeFlags; diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c index 03b281a771..2c7dcf7d2a 100644 --- a/src/udev/udev-builtin-net_id.c +++ b/src/udev/udev-builtin-net_id.c @@ -31,6 +31,7 @@ * — USB port number chain * v - VIO slot number (IBM PowerVM) * ai — Platform bus ACPI instance id + * in — Netdevsim bus address and port name * * All multi-function PCI devices will carry the [f] number in the * device name, including the function 0 device. @@ -126,6 +127,7 @@ enum netname_type{ NET_CCW, NET_VIO, NET_PLATFORM, + NET_NETDEVSIM, }; struct netnames { @@ -145,6 +147,7 @@ struct netnames { char ccw_busid[IFNAMSIZ]; char vio_slot[IFNAMSIZ]; char platform_path[IFNAMSIZ]; + char netdevsim_path[IFNAMSIZ]; }; struct virtfn_info { @@ -794,6 +797,43 @@ static int names_mac(sd_device *dev, struct netnames *names) { return 0; } +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; +} + /* IEEE Organizationally Unique Identifier vendor string */ static int ieee_oui(sd_device *dev, struct netnames *names, bool test) { char str[32]; @@ -897,6 +937,16 @@ static int builtin_net_id(sd_device *dev, int argc, char *argv[], bool test) { return 0; } + /* get netdevsim path names */ + if (names_netdevsim(dev, &names) >= 0 && names.type == NET_NETDEVSIM) { + char str[IFNAMSIZ]; + + 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; + } + /* get PCI based path names, we compose only PCI based paths */ if (names_pci(dev, &names) < 0) return 0;